Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PHP coding standard 2.4.0 #156

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

### Changed
* Extract configuration-related code from `EntityManagerFactory` into `ConfigurationFactory`.
* Update to shlinkio coding standard 2.4.

### Deprecated
* *Nothing*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"phpunit/phpunit": "^11.3",
"psr/simple-cache": "^3.0",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.3.0",
"shlinkio/php-coding-standard": "~2.4.0",
"symfony/var-dumper": "^7.1"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion functions/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function array_pad;
use function explode;

function buildDateRange(?Chronos $startDate, ?Chronos $endDate): DateRange
function buildDateRange(Chronos|null $startDate, Chronos|null $endDate): DateRange
{
return match (true) {
$startDate !== null && $endDate !== null => DateRange::between($startDate, $endDate),
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CacheFactory
{
private Closure $apcuEnabled;

public function __construct(?callable $apcuEnabled = null)
public function __construct(callable|null $apcuEnabled = null)
{
$this->apcuEnabled = Closure::fromCallable($apcuEnabled ?? static fn () => extension_loaded('apcu'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function normalizeServer(string $server): array
return $parsedServer;
}

private function resolveOptions(array $redisConfig, array $servers): ?array
private function resolveOptions(array $redisConfig, array $servers): array|null
{
$sentinelService = $redisConfig['sentinel_service'] ?? null;
if ($sentinelService !== null) {
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Type/ChronosDateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getName(): string
/**
* @throws ConversionException
*/
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Chronos
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): Chronos|null
{
if ($value === null) {
return null;
Expand All @@ -39,7 +39,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Ch
* @template T
* @throws ConversionException
*/
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): string|null
{
if ($value === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

abstract class AbstractEntity
{
protected ?string $id = null;
protected string|null $id = null;

public function getId(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lock/NamespacedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NamespacedStore implements SharedLockStoreInterface
{
public function __construct(
private readonly SharedLockStoreInterface $wrappedStore,
private readonly ?string $namespace = null,
private readonly string|null $namespace = null,
/** Some stores may not allow default separator value. Make sure you provide the appropriate one */
private readonly string $namespaceSeparator = ':',
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mercure/JwtProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public function buildPublishToken(): string;
/**
* @return non-empty-string
*/
public function buildSubscriptionToken(?DateTimeImmutable $expiresAt = null): string;
public function buildSubscriptionToken(DateTimeImmutable|null $expiresAt = null): string;
}
2 changes: 1 addition & 1 deletion src/Mercure/LcobucciJwtProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function buildPublishToken(): string
/**
* @return non-empty-string
*/
public function buildSubscriptionToken(?DateTimeImmutable $expiresAt = null): string
public function buildSubscriptionToken(DateTimeImmutable|null $expiresAt = null): string
{
$expiresAt = $this->roundDateToTheSecond($expiresAt ?? Chronos::now()->addDays(3));
return $this->buildToken(['subscribe' => ['*']], $expiresAt);
Expand Down
6 changes: 3 additions & 3 deletions src/Mercure/MercureOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* @param non-empty-string $jwtIssuer
*/
public function __construct(
public ?string $publicHubUrl = null,
public ?string $internalHubUrl = null,
public ?string $jwtSecret = null,
public string|null $publicHubUrl = null,
public string|null $internalHubUrl = null,
public string|null $jwtSecret = null,
public string $jwtIssuer = 'Shlink',
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Paginator/Util/PagerfantaUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class PagerfantaUtils
*/
public static function serializePaginator(
Pagerfanta $paginator,
?callable $serializer = null,
callable|null $serializer = null,
string $dataProp = 'data',
): array {
$currentPageItems = ArrayUtils::iteratorToArray($paginator->getCurrentPageResults());
Expand All @@ -43,7 +43,7 @@ public static function serializePaginator(
* @param T[] $items
* @param null|callable(T): array $serializer
*/
private static function serializeItems(array $items, ?callable $serializer = null): array
private static function serializeItems(array $items, callable|null $serializer = null): array
{
return $serializer === null ? $items : array_map($serializer, $items);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Paginator/Util/PagerfantaUtilsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait PagerfantaUtilsTrait
*/
private function serializePaginator(
Pagerfanta $paginator,
?DataTransformerInterface $transformer = null,
DataTransformerInterface|null $transformer = null,
string $dataProp = 'data',
): array {
$serializer = $transformer !== null ? fn ($value) => $transformer->transform($value) : null;
Expand Down
4 changes: 2 additions & 2 deletions src/Util/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Cake\Chronos\Chronos;

final class DateRange
final readonly class DateRange
{
private function __construct(public readonly ?Chronos $startDate = null, public readonly ?Chronos $endDate = null)
private function __construct(public Chronos|null $startDate = null, public Chronos|null $endDate = null)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validation/HostAndPortValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HostAndPortValidator extends AbstractValidator
private ValidatorInterface $hostValidator;
private ValidatorInterface $portValidator;

public function __construct(?array $options = null)
public function __construct(array|null $options = null)
{
parent::__construct($options);

Expand Down
2 changes: 1 addition & 1 deletion src/Validation/InputFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function date(
return $input;
}

public static function numeric(string $name, ?int $min = 1, bool $required = false): Input
public static function numeric(string $name, int|null $min = 1, bool $required = false): Input
{
$input = self::basic($name, $required);
$input->getValidatorChain()->attach(new Validator\Callback(fn ($value) => is_numeric($value)))
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/SluggerFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SluggerFilter implements FilterInterface
{
private Slugger\SluggerInterface $slugger;

public function __construct(?Slugger\SluggerInterface $slugger = null)
public function __construct(Slugger\SluggerInterface|null $slugger = null)
{
$this->slugger = $slugger ?? new Slugger\AsciiSlugger();
}
Expand Down
10 changes: 5 additions & 5 deletions test/Cache/RedisFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setUp(): void
*/
#[Test, DataProvider('provideRedisConfig')]
public function createsRedisClientBasedOnCacheConfig(
?array $config,
array|null $config,
string $expectedCluster,
string $expectedReplication,
): void {
Expand Down Expand Up @@ -117,9 +117,9 @@ public function exceptionIsThrownIfServerUriHasInvalidFormat(): void
#[Test, DataProvider('provideServersWithCredentials')]
public function providedCredentialsArePassedToConnection(
array $redisConfig,
?string $expectedUsername,
?string $expectedPassword,
?array $expectedSslOptions,
string|null $expectedUsername,
string|null $expectedPassword,
array|null $expectedSslOptions,
): void {
$this->container->expects($this->once())->method('get')->with('config')->willReturn([
'cache' => ['redis' => $redisConfig],
Expand Down Expand Up @@ -161,7 +161,7 @@ public static function provideServersWithCredentials(): iterable
#[Test, DataProvider('provideServersWithDatabases')]
public function databaseConfigurationIsApplied(
array $redisConfig,
?int $expectedDatabase,
int|null $expectedDatabase,
): void {
$this->container->expects($this->once())->method('get')->with('config')->willReturn([
'cache' => ['redis' => $redisConfig],
Expand Down
4 changes: 2 additions & 2 deletions test/Doctrine/Type/ChronosDateTimeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function nameIsReturned(): void
* @param class-string<Chronos>|null $expected
*/
#[Test, DataProvider('provideValues')]
public function valueIsConverted(?string $value, ?string $expected): void
public function valueIsConverted(string|null $value, string|null $expected): void
{
$platform = $this->createMock(AbstractPlatform::class);
$platform->method('getDateTimeFormatString')->willReturn('Y-m-d H:i:s');
Expand All @@ -64,7 +64,7 @@ public static function provideValues(): iterable
}

#[Test, DataProvider('providePhpValues')]
public function valueIsConvertedToDatabaseFormat(?DateTimeInterface $value, ?string $expected): void
public function valueIsConvertedToDatabaseFormat(DateTimeInterface|null $value, string|null $expected): void
{
$platform = $this->createMock(AbstractPlatform::class);
$platform->method('getDateTimeFormatString')->willReturn('Y-m-d');
Expand Down
7 changes: 5 additions & 2 deletions test/Functions/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
class FunctionsTest extends TestCase
{
#[Test, DataProvider('provideDates')]
public function expectedDateRangeIsBuilt(?Chronos $startDate, ?Chronos $endDate, bool $expectedIsAllTime): void
{
public function expectedDateRangeIsBuilt(
Chronos|null $startDate,
Chronos|null $endDate,
bool $expectedIsAllTime,
): void {
$dateRange = buildDateRange($startDate, $endDate);

self::assertEquals($expectedIsAllTime, $dateRange->isAllTime());
Expand Down
2 changes: 1 addition & 1 deletion test/Lock/NamespacedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp(): void

#[Test, DataProvider('provideKeysAndNamespaces')]
public function keyIsReturnedVerbatimWhenNoNamespacesIsProvided(
?string $namespace,
string|null $namespace,
Key $key,
string $expectedResource,
): void {
Expand Down
2 changes: 1 addition & 1 deletion test/Mercure/LcobucciJwtProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function provideMercureConfigs(): iterable
}

#[Test, DataProvider('provideExpirationDates')]
public function expectedSubscriptionTokenIsCreated(?Chronos $expiresAt, Chronos $expectedExpiresAt): void
public function expectedSubscriptionTokenIsCreated(Chronos|null $expiresAt, Chronos $expectedExpiresAt): void
{
/** @var UnencryptedToken $token */
$token = $this->jwtConfig->parser()->parse(
Expand Down
2 changes: 1 addition & 1 deletion test/Mercure/MercureOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class MercureOptionsTest extends TestCase
{
#[Test, DataProvider('providePublicHubUrls')]
public function isEnabledOnlyWHenPublicUrlExists(?string $publicHubUrl, bool $expectedIsEnabled): void
public function isEnabledOnlyWHenPublicUrlExists(string|null $publicHubUrl, bool $expectedIsEnabled): void
{
$options = new MercureOptions(publicHubUrl: $publicHubUrl);
self::assertEquals($options->isEnabled(), $expectedIsEnabled);
Expand Down
2 changes: 1 addition & 1 deletion test/Validation/SluggerFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp(): void
}

#[Test, DataProvider('provideValuesToFilter')]
public function providedValueIsFilteredAsExpected(?string $providedValue, ?string $expectedValue): void
public function providedValueIsFilteredAsExpected(string|null $providedValue, string|null $expectedValue): void
{
$this->slugger->expects($this->exactly($expectedValue !== null ? 1 : 0))->method('slug')->with(
$providedValue,
Expand Down