From 39b920a7c58913f95162b92c4e178366eb9d5a01 Mon Sep 17 00:00:00 2001 From: Phillip Look Date: Tue, 6 May 2025 12:41:24 +0200 Subject: [PATCH 1/2] fix: Update dependencies (fix phpstan/rector issues) --- .github/workflows/build.yml | 1 - composer.json | 23 +++++++++++------------ phpstan.neon.dist | 1 - src/InvalidValue.php | 2 +- src/NotConvertable.php | 2 +- src/TypeGuard.php | 6 ++++-- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62179a2..987bda7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,6 @@ jobs: strategy: matrix: php-version: - - "8.2" - "8.3" - "8.4" diff --git a/composer.json b/composer.json index e171ebd..423fc8e 100644 --- a/composer.json +++ b/composer.json @@ -10,20 +10,19 @@ } ], "require": { - "php": "^8.2" + "php": "^8.3" }, "require-dev": { - "brainbits/phpcs-standard": "^7.0.2", - "brainbits/phpstan-rules": "^3.1.2", - "ergebnis/phpstan-rules": "^2.5.2", - "thecodingmachine/phpstan-safe-rule": "^1.2.0", - "thecodingmachine/phpstan-strict-rules": "^1.0.0", - "phpstan/phpstan-phpunit": "^1.4.2", - "squizlabs/php_codesniffer": "^3.11.3", - "phpstan/phpstan": "^1.12.19", - "phpstan/phpstan-strict-rules": "^1.6.2", - "phpunit/phpunit": "^11.5.10", - "rector/rector": "^1.2.10" + "brainbits/phpcs-standard": "^8.0.0", + "brainbits/phpstan-rules": "^4.0.0", + "ergebnis/phpstan-rules": "^2.8.0", + "thecodingmachine/phpstan-safe-rule": "^1.4.0", + "phpstan/phpstan-phpunit": "^2.0.6", + "squizlabs/php_codesniffer": "^3.12.2", + "phpstan/phpstan": "^2.1.14", + "phpstan/phpstan-strict-rules": "^2.0.4", + "phpunit/phpunit": "^12.1.4", + "rector/rector": "^2.0.15" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d377b1b..6d00fc0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -21,4 +21,3 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon diff --git a/src/InvalidValue.php b/src/InvalidValue.php index e566d79..9520156 100644 --- a/src/InvalidValue.php +++ b/src/InvalidValue.php @@ -26,7 +26,7 @@ private static function withMessage(string $message): self $line = $trace['line'] ?? null; if ($file !== null && $line !== null && !str_contains($file, __DIR__)) { - $me->message = sprintf('%s in %s:%s', $me->message, basename($file), $line); + $me->message = sprintf('%s in %s:%s', $message, basename($file), $line); break; } } diff --git a/src/NotConvertable.php b/src/NotConvertable.php index aef6fbc..b3ab85f 100644 --- a/src/NotConvertable.php +++ b/src/NotConvertable.php @@ -47,7 +47,7 @@ private static function withMessage(string $message): self $line = $trace['line'] ?? null; if ($file !== null && $line !== null && !str_contains($file, __DIR__)) { - $me->message = sprintf('%s in %s:%s', $me->message, basename($file), $line); + $me->message = sprintf('%s in %s:%s', $message, basename($file), $line); break; } } diff --git a/src/TypeGuard.php b/src/TypeGuard.php index b9ed289..c8dacd6 100644 --- a/src/TypeGuard.php +++ b/src/TypeGuard.php @@ -21,11 +21,13 @@ final class TypeGuard private string $dateTimeFormat = 'c'; + private static TypeGuard $typeGuard; + public static function instance(): self { - static $instance = new self(); + self::$typeGuard ??= new self(); - return $instance; + return self::$typeGuard; } /** @return ($value is null ? null : bool) */ From 98cb9390cae536b7069a5cae64309457f6f7702f Mon Sep 17 00:00:00 2001 From: Phillip Look Date: Tue, 6 May 2025 12:50:50 +0200 Subject: [PATCH 2/2] test: Fix CoversFunction attribute --- tests/AsBoolTest.php | 2 +- tests/AsDateTimeImmutableTest.php | 4 ++-- tests/AsDateTimeStringTest.php | 6 +++--- tests/AsFloatTest.php | 2 +- tests/AsIntTest.php | 2 +- tests/AsStringTest.php | 2 +- tests/BlankAsNullTest.php | 2 +- tests/FalseAsNullTest.php | 2 +- tests/FalsyAsNullTest.php | 2 +- tests/NotNullTest.php | 2 +- tests/ZeroAsNullTest.php | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/AsBoolTest.php b/tests/AsBoolTest.php index 95461f4..59d53ae 100644 --- a/tests/AsBoolTest.php +++ b/tests/AsBoolTest.php @@ -18,7 +18,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asBool')] +#[CoversFunction('Plook\TypeGuard\asBool')] final class AsBoolTest extends TestCase { public function testDoesNotTouchBools(): void diff --git a/tests/AsDateTimeImmutableTest.php b/tests/AsDateTimeImmutableTest.php index ab09fa9..531959e 100644 --- a/tests/AsDateTimeImmutableTest.php +++ b/tests/AsDateTimeImmutableTest.php @@ -19,8 +19,8 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asDateTimeImmutable')] -#[CoversFunction('\Plook\TypeGuard\asString')] +#[CoversFunction('Plook\TypeGuard\asDateTimeImmutable')] +#[CoversFunction('Plook\TypeGuard\asString')] final class AsDateTimeImmutableTest extends TestCase { private readonly DateTimeZone $originalTimeZone; diff --git a/tests/AsDateTimeStringTest.php b/tests/AsDateTimeStringTest.php index 1b9c316..05f2ec3 100644 --- a/tests/AsDateTimeStringTest.php +++ b/tests/AsDateTimeStringTest.php @@ -17,9 +17,9 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asDateTimeString')] -#[CoversFunction('\Plook\TypeGuard\asDateTimeImmutable')] -#[CoversFunction('\Plook\TypeGuard\asString')] +#[CoversFunction('Plook\TypeGuard\asDateTimeString')] +#[CoversFunction('Plook\TypeGuard\asDateTimeImmutable')] +#[CoversFunction('Plook\TypeGuard\asString')] final class AsDateTimeStringTest extends TestCase { private readonly string $originalDateTimeFormat; diff --git a/tests/AsFloatTest.php b/tests/AsFloatTest.php index ecea3c7..97e8235 100644 --- a/tests/AsFloatTest.php +++ b/tests/AsFloatTest.php @@ -17,7 +17,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asFloat')] +#[CoversFunction('Plook\TypeGuard\asFloat')] final class AsFloatTest extends TestCase { public function testDoesNotTouchFloats(): void diff --git a/tests/AsIntTest.php b/tests/AsIntTest.php index 9167de3..630d84c 100644 --- a/tests/AsIntTest.php +++ b/tests/AsIntTest.php @@ -17,7 +17,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asInt')] +#[CoversFunction('Plook\TypeGuard\asInt')] final class AsIntTest extends TestCase { public function testDoesNotTouchInts(): void diff --git a/tests/AsStringTest.php b/tests/AsStringTest.php index 3b2723c..0f02642 100644 --- a/tests/AsStringTest.php +++ b/tests/AsStringTest.php @@ -17,7 +17,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\asString')] +#[CoversFunction('Plook\TypeGuard\asString')] final class AsStringTest extends TestCase { public function testDoesNotTouchStrings(): void diff --git a/tests/BlankAsNullTest.php b/tests/BlankAsNullTest.php index 560dd69..d5e6d80 100644 --- a/tests/BlankAsNullTest.php +++ b/tests/BlankAsNullTest.php @@ -15,7 +15,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\blankAsNull')] +#[CoversFunction('Plook\TypeGuard\blankAsNull')] final class BlankAsNullTest extends TestCase { public function testConvertsBlankToNull(): void diff --git a/tests/FalseAsNullTest.php b/tests/FalseAsNullTest.php index 2c28973..f900c89 100644 --- a/tests/FalseAsNullTest.php +++ b/tests/FalseAsNullTest.php @@ -15,7 +15,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\falseAsNull')] +#[CoversFunction('Plook\TypeGuard\falseAsNull')] final class FalseAsNullTest extends TestCase { public function testConvertsFalseToNull(): void diff --git a/tests/FalsyAsNullTest.php b/tests/FalsyAsNullTest.php index 6e22705..2a3c4cc 100644 --- a/tests/FalsyAsNullTest.php +++ b/tests/FalsyAsNullTest.php @@ -15,7 +15,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\falsyAsNull')] +#[CoversFunction('Plook\TypeGuard\falsyAsNull')] final class FalsyAsNullTest extends TestCase { public function testConvertsBlankToNull(): void diff --git a/tests/NotNullTest.php b/tests/NotNullTest.php index 82bd00e..518acd2 100644 --- a/tests/NotNullTest.php +++ b/tests/NotNullTest.php @@ -17,7 +17,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(InvalidValue::class)] -#[CoversFunction('\Plook\TypeGuard\notNull')] +#[CoversFunction('Plook\TypeGuard\notNull')] final class NotNullTest extends TestCase { public function testDoesNotTouchInts(): void diff --git a/tests/ZeroAsNullTest.php b/tests/ZeroAsNullTest.php index 79cd499..c55a7f4 100644 --- a/tests/ZeroAsNullTest.php +++ b/tests/ZeroAsNullTest.php @@ -15,7 +15,7 @@ #[CoversClass(TypeGuard::class)] #[CoversClass(NotConvertable::class)] -#[CoversFunction('\Plook\TypeGuard\zeroAsNull')] +#[CoversFunction('Plook\TypeGuard\zeroAsNull')] final class ZeroAsNullTest extends TestCase { public function testConvertsZeroIntToNull(): void