diff --git a/composer.json b/composer.json index 50bfd0da..edeb48fb 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "doctrine/coding-standard": "^9.0.0", "php-standard-library/psalm-plugin": "^1.1.1", "phpunit/phpunit": "^9.5.10", + "psalm/plugin-phpunit": "^0.16.1", "roave/infection-static-analysis-plugin": "^1.10", "roave/security-advisories": "dev-master", "squizlabs/php_codesniffer": "^3.6.1", diff --git a/composer.lock b/composer.lock index 315c28a9..4681d700 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7a5dcc0fead6209c696b336ad59bd0cc", + "content-hash": "9fbf22a18367cd78eef22c43a7948309", "packages": [ { "name": "azjezz/psl", @@ -4223,6 +4223,66 @@ ], "time": "2021-09-25T07:38:51+00:00" }, + { + "name": "psalm/plugin-phpunit", + "version": "0.16.1", + "source": { + "type": "git", + "url": "https://github.com/psalm/psalm-plugin-phpunit.git", + "reference": "5dd3be04f37a857d52880ef6af2524a441dfef24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/psalm/psalm-plugin-phpunit/zipball/5dd3be04f37a857d52880ef6af2524a441dfef24", + "reference": "5dd3be04f37a857d52880ef6af2524a441dfef24", + "shasum": "" + }, + "require": { + "composer/package-versions-deprecated": "^1.10", + "composer/semver": "^1.4 || ^2.0 || ^3.0", + "ext-simplexml": "*", + "php": "^7.1 || ^8.0", + "vimeo/psalm": "dev-master || dev-4.x || ^4.5" + }, + "conflict": { + "phpunit/phpunit": "<7.5" + }, + "require-dev": { + "codeception/codeception": "^4.0.3", + "php": "^7.3 || ^8.0", + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", + "squizlabs/php_codesniffer": "^3.3.1", + "weirdan/codeception-psalm-module": "^0.11.0", + "weirdan/prophecy-shim": "^1.0 || ^2.0" + }, + "type": "psalm-plugin", + "extra": { + "psalm": { + "pluginClass": "Psalm\\PhpUnitPlugin\\Plugin" + } + }, + "autoload": { + "psr-4": { + "Psalm\\PhpUnitPlugin\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Brown", + "email": "github@muglug.com" + } + ], + "description": "Psalm plugin for PHPUnit", + "support": { + "issues": "https://github.com/psalm/psalm-plugin-phpunit/issues", + "source": "https://github.com/psalm/psalm-plugin-phpunit/tree/0.16.1" + }, + "time": "2021-06-18T23:56:46+00:00" + }, { "name": "roave/infection-static-analysis-plugin", "version": "1.10.0", diff --git a/psalm.xml b/psalm.xml index 4682e7e6..71f01eb7 100644 --- a/psalm.xml +++ b/psalm.xml @@ -11,15 +11,31 @@ + + + - - - + + + + + + + + + + + + + + + - + + diff --git a/src/DetectChanges/BCBreak/FunctionBased/FunctionBased.php b/src/DetectChanges/BCBreak/FunctionBased/FunctionBased.php index ced4e469..5fd756c2 100644 --- a/src/DetectChanges/BCBreak/FunctionBased/FunctionBased.php +++ b/src/DetectChanges/BCBreak/FunctionBased/FunctionBased.php @@ -11,10 +11,10 @@ interface FunctionBased { /** - * @template T of ReflectionMethod|ReflectionFunction - * * @param T $fromFunction * @param T $toFunction + * + * @template T of ReflectionMethod|ReflectionFunction */ public function __invoke( ReflectionMethod|ReflectionFunction $fromFunction, diff --git a/src/DetectChanges/BCBreak/FunctionBased/MultipleChecksOnAFunction.php b/src/DetectChanges/BCBreak/FunctionBased/MultipleChecksOnAFunction.php index 3753b87e..d31a4893 100644 --- a/src/DetectChanges/BCBreak/FunctionBased/MultipleChecksOnAFunction.php +++ b/src/DetectChanges/BCBreak/FunctionBased/MultipleChecksOnAFunction.php @@ -27,12 +27,12 @@ public function __invoke( } /** - * @template T of ReflectionMethod|ReflectionFunction - * * @param T $fromFunction * @param T $toFunction * * @return iterable + * + * @template T of ReflectionMethod|ReflectionFunction */ private function multipleChecks( ReflectionMethod|ReflectionFunction $fromFunction, diff --git a/src/DetectChanges/BCBreak/PropertyBased/PropertyTypeChanged.php b/src/DetectChanges/BCBreak/PropertyBased/PropertyTypeChanged.php index cf0336dd..05c82e5d 100644 --- a/src/DetectChanges/BCBreak/PropertyBased/PropertyTypeChanged.php +++ b/src/DetectChanges/BCBreak/PropertyBased/PropertyTypeChanged.php @@ -5,7 +5,6 @@ namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased; use Psl\Str; -use Psl\Vec; use Roave\BackwardCompatibility\Change; use Roave\BackwardCompatibility\Changes; use Roave\BackwardCompatibility\DetectChanges\Variance\TypeIsContravariant; @@ -13,8 +12,6 @@ use Roave\BackwardCompatibility\Formatter\ReflectionPropertyName; use Roave\BetterReflection\Reflection\ReflectionProperty; -use function array_merge; - /** * Type declarations for properties are invariant: you can't restrict the type because the consumer may * write invalid values to it, and you cannot widen the type because the consumer may expect a specific diff --git a/src/Git/CheckedOutRepository.php b/src/Git/CheckedOutRepository.php index c00faf4d..35cce718 100644 --- a/src/Git/CheckedOutRepository.php +++ b/src/Git/CheckedOutRepository.php @@ -9,9 +9,7 @@ final class CheckedOutRepository { - private string $path; - - private function __construct() + private function __construct(private string $path) { } @@ -19,10 +17,7 @@ public static function fromPath(string $path): self { Psl\invariant(Filesystem\is_directory($path . '/.git'), 'Directory "%s" is not a GIT repository.', $path); - $instance = new self(); - $instance->path = $path; - - return $instance; + return new self($path); } public function __toString(): string diff --git a/src/Git/Revision.php b/src/Git/Revision.php index 0f340c89..20146acb 100644 --- a/src/Git/Revision.php +++ b/src/Git/Revision.php @@ -7,12 +7,12 @@ use Psl; use Psl\Regex; use Psl\Str; +use Psl\Type; final class Revision { - private string $sha1; - - private function __construct() + /** @param non-empty-string $sha1 */ + private function __construct(private string $sha1) { } @@ -20,10 +20,10 @@ public static function fromSha1(string $sha1): self { Psl\invariant(Regex\matches($sha1, '/^[a-zA-Z0-9]{40}$/'), 'Invalid SHA1 hash.'); - $instance = new self(); - $instance->sha1 = Str\trim_right($sha1); - - return $instance; + return new self( + Type\non_empty_string() + ->assert(Str\trim_right($sha1)) + ); } public function __toString(): string diff --git a/test/unit/DetectChanges/BCBreak/ClassBased/AncestorRemovedTest.php b/test/unit/DetectChanges/BCBreak/ClassBased/AncestorRemovedTest.php index 58ee700b..10c369d8 100644 --- a/test/unit/DetectChanges/BCBreak/ClassBased/AncestorRemovedTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassBased/AncestorRemovedTest.php @@ -132,14 +132,11 @@ class ClassWithInvertedInterfaceNames implements IG, IE {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameAbstractTest.php b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameAbstractTest.php index f8c41c6a..6bc700ac 100644 --- a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameAbstractTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameAbstractTest.php @@ -99,14 +99,11 @@ interface AbstractToInterface {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameInterfaceTest.php b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameInterfaceTest.php index 214b32b0..9635d4cc 100644 --- a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameInterfaceTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameInterfaceTest.php @@ -105,14 +105,11 @@ trait TraitToTrait {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameTraitTest.php b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameTraitTest.php index 742843d9..ad5868ba 100644 --- a/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameTraitTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassBased/ClassBecameTraitTest.php @@ -108,14 +108,11 @@ trait TraitToTrait {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantValueChangedTest.php b/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantValueChangedTest.php index 672f9680..601c2c9c 100644 --- a/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantValueChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantValueChangedTest.php @@ -5,6 +5,7 @@ namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased; use PHPUnit\Framework\TestCase; +use Psl\Type; use Roave\BackwardCompatibility\Change; use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantValueChanged; use Roave\BetterReflection\BetterReflection; @@ -25,7 +26,7 @@ final class ClassConstantValueChangedTest extends TestCase /** * @param string[] $expectedMessages * - * @dataProvider propertiesToBeTested + * @dataProvider constantsToBeTested */ public function testDiffs( ReflectionClassConstant $fromConstant, @@ -43,10 +44,13 @@ public function testDiffs( } /** - * @return array>> - * @psalm-return array}> + * @return array + * }> */ - public function propertiesToBeTested(): array + public function constantsToBeTested(): array { $astLocator = (new BetterReflection())->astLocator(); @@ -123,14 +127,13 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $constant, array $errorMessages) use ($fromClass, $toClass): array { - return [ - $fromClass->getReflectionConstant($constant), - $toClass->getReflectionConstant($constant), - $errorMessages, - ]; - }, + static fn (string $constant, array $errorMessages): array => [ + Type\object(ReflectionClassConstant::class) + ->coerce($fromClass->getReflectionConstant($constant)), + Type\object(ReflectionClassConstant::class) + ->coerce($toClass->getReflectionConstant($constant)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantVisibilityReducedTest.php b/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantVisibilityReducedTest.php index 4390be42..da921ad4 100644 --- a/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantVisibilityReducedTest.php +++ b/test/unit/DetectChanges/BCBreak/ClassConstantBased/ClassConstantVisibilityReducedTest.php @@ -5,13 +5,13 @@ namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased; use PHPUnit\Framework\TestCase; +use Psl\Type; use Roave\BackwardCompatibility\Change; use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantVisibilityReduced; use Roave\BetterReflection\BetterReflection; use Roave\BetterReflection\Reflection\ReflectionClassConstant; use Roave\BetterReflection\Reflector\DefaultReflector; use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; -use RoaveTest\BackwardCompatibility\TypeRestriction; use function array_map; use function iterator_to_array; use function array_combine; @@ -22,7 +22,7 @@ final class ClassConstantVisibilityReducedTest extends TestCase { /** - * @dataProvider propertiesToBeTested + * @dataProvider constantsToBeTested * * @param string[] $expectedMessages */ @@ -42,11 +42,13 @@ public function testDiffs( } /** - * @return array>> - * - * @psalm-return array}> + * @return array + * }> */ - public function propertiesToBeTested() : array + public function constantsToBeTested() : array { $astLocator = (new BetterReflection())->astLocator(); @@ -117,14 +119,13 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - function (string $constant, array $errorMessages) use ($fromClass, $toClass) : array { - return [ - $fromClass->getReflectionConstant($constant), - $toClass->getReflectionConstant($constant), - $errorMessages, - ]; - }, + static fn (string $constant, array $errorMessages): array => [ + Type\object(ReflectionClassConstant::class) + ->coerce($fromClass->getReflectionConstant($constant)), + Type\object(ReflectionClassConstant::class) + ->coerce($toClass->getReflectionConstant($constant)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/FunctionBecameInternalTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/FunctionBecameInternalTest.php index f9775dd7..0f66d491 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/FunctionBecameInternalTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/FunctionBecameInternalTest.php @@ -95,14 +95,11 @@ function d() {} return array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterByReferenceChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterByReferenceChangedTest.php index c40172a3..aa34aad0 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterByReferenceChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterByReferenceChangedTest.php @@ -123,14 +123,11 @@ function changed2(& $a) {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterDefaultValueChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterDefaultValueChangedTest.php index 42b60d40..65986603 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterDefaultValueChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterDefaultValueChangedTest.php @@ -123,14 +123,11 @@ function changed2($a = 2) {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeChangedTest.php index 674741b2..29b6ce70 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeChangedTest.php @@ -156,14 +156,11 @@ function changed2(int $a, int $b) {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php index c2ab8f6e..3911514f 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ParameterTypeContravarianceChangedTest.php @@ -157,14 +157,11 @@ function changed2(int $a, int $b) {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/RequiredParameterAmountIncreasedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/RequiredParameterAmountIncreasedTest.php index 3b896c83..e0c7ae38 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/RequiredParameterAmountIncreasedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/RequiredParameterAmountIncreasedTest.php @@ -128,14 +128,11 @@ function changed2($a, $b, $c, $d) {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeByReferenceChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeByReferenceChangedTest.php index 7f251006..9e0d5ca1 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeByReferenceChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeByReferenceChangedTest.php @@ -114,14 +114,11 @@ function & changed2() {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeChangedTest.php index 75c6b9c4..b0ee7598 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeChangedTest.php @@ -152,14 +152,11 @@ function changed2() {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeCovarianceChangedTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeCovarianceChangedTest.php index 51989efc..e334f694 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeCovarianceChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/ReturnTypeCovarianceChangedTest.php @@ -153,14 +153,11 @@ function changed2() {} array_combine( array_keys($functions), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { - return [ - $fromReflector->reflectFunction($function), - $toReflector->reflectFunction($function), - $errorMessages, - ]; - }, + static fn (string $function, array $errors): array => [ + $fromReflector->reflectFunction($function), + $toReflector->reflectFunction($function), + $errors, + ], array_keys($functions), $functions ) diff --git a/test/unit/DetectChanges/BCBreak/FunctionBased/SkipFunctionBasedErrorsTest.php b/test/unit/DetectChanges/BCBreak/FunctionBased/SkipFunctionBasedErrorsTest.php index b42656d4..b5ff7c13 100644 --- a/test/unit/DetectChanges/BCBreak/FunctionBased/SkipFunctionBasedErrorsTest.php +++ b/test/unit/DetectChanges/BCBreak/FunctionBased/SkipFunctionBasedErrorsTest.php @@ -11,8 +11,8 @@ use Roave\BackwardCompatibility\Changes; use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\FunctionBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\SkipFunctionBasedErrors; - use Roave\BetterReflection\Reflection\ReflectionFunction; + use function uniqid; /** diff --git a/test/unit/DetectChanges/BCBreak/InterfaceBased/AncestorRemovedTest.php b/test/unit/DetectChanges/BCBreak/InterfaceBased/AncestorRemovedTest.php index 5a3da30d..b03a4401 100644 --- a/test/unit/DetectChanges/BCBreak/InterfaceBased/AncestorRemovedTest.php +++ b/test/unit/DetectChanges/BCBreak/InterfaceBased/AncestorRemovedTest.php @@ -98,14 +98,11 @@ interface ParentInterfaceOrderSwapped extends ID, IA {} return array_combine( array_keys($interfaces), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $interfaceName, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($interfaceName), - $toReflector->reflectClass($interfaceName), - $errors, - ]; - }, + static fn (string $interfaceName, array $errors): array => [ + $fromReflector->reflectClass($interfaceName), + $toReflector->reflectClass($interfaceName), + $errors, + ], array_keys($interfaces), $interfaces ) diff --git a/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameClassTest.php b/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameClassTest.php index 91319f5f..71202467 100644 --- a/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameClassTest.php +++ b/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameClassTest.php @@ -105,14 +105,11 @@ trait TraitToTrait {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $interfaceName, array $errors): array => [ + $fromReflector->reflectClass($interfaceName), + $toReflector->reflectClass($interfaceName), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameTraitTest.php b/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameTraitTest.php index ce18c5d2..ce9fc26e 100644 --- a/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameTraitTest.php +++ b/test/unit/DetectChanges/BCBreak/InterfaceBased/InterfaceBecameTraitTest.php @@ -105,14 +105,11 @@ trait TraitToTrait {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $interfaceName, array $errors): array => [ + $fromReflector->reflectClass($interfaceName), + $toReflector->reflectClass($interfaceName), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/InterfaceBased/MethodAddedTest.php b/test/unit/DetectChanges/BCBreak/InterfaceBased/MethodAddedTest.php index 39ae7912..f686aba5 100644 --- a/test/unit/DetectChanges/BCBreak/InterfaceBased/MethodAddedTest.php +++ b/test/unit/DetectChanges/BCBreak/InterfaceBased/MethodAddedTest.php @@ -119,15 +119,11 @@ public function c() {} return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errorMessages) use ($fromClassReflector, $toClassReflector - ): array { - return [ - $fromClassReflector->reflectClass($className), - $toClassReflector->reflectClass($className), - $errorMessages, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromClassReflector->reflectClass($className), + $toClassReflector->reflectClass($className), + $errors, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/MethodBased/MethodBecameFinalTest.php b/test/unit/DetectChanges/BCBreak/MethodBased/MethodBecameFinalTest.php index c500a631..3f3e5f45 100644 --- a/test/unit/DetectChanges/BCBreak/MethodBased/MethodBecameFinalTest.php +++ b/test/unit/DetectChanges/BCBreak/MethodBased/MethodBecameFinalTest.php @@ -125,14 +125,11 @@ private final function privateFinalToFinal() {} return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $methodName, array $errorMessages) use ($fromClass, $toClass): array { - return [ - $fromClass->getMethod($methodName), - $toClass->getMethod($methodName), - $errorMessages, - ]; - }, + static fn (string $methodName, array $errors): array => [ + $fromClass->getMethod($methodName), + $toClass->getMethod($methodName), + $errors, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/MethodBased/MethodConcretenessChangedTest.php b/test/unit/DetectChanges/BCBreak/MethodBased/MethodConcretenessChangedTest.php index 79d31515..15d70a1f 100644 --- a/test/unit/DetectChanges/BCBreak/MethodBased/MethodConcretenessChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/MethodBased/MethodConcretenessChangedTest.php @@ -125,14 +125,11 @@ private abstract function privateAbstractToAbstract() {} return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $methodName, array $errorMessages) use ($fromClass, $toClass): array { - return [ - $fromClass->getMethod($methodName), - $toClass->getMethod($methodName), - $errorMessages, - ]; - }, + static fn (string $methodName, array $errors): array => [ + $fromClass->getMethod($methodName), + $toClass->getMethod($methodName), + $errors, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/MethodBased/MethodScopeChangedTest.php b/test/unit/DetectChanges/BCBreak/MethodBased/MethodScopeChangedTest.php index e622d456..14d15e9a 100644 --- a/test/unit/DetectChanges/BCBreak/MethodBased/MethodScopeChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/MethodBased/MethodScopeChangedTest.php @@ -125,14 +125,11 @@ private static function privateStaticToStatic() {} return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $methodName, array $errorMessages) use ($fromClass, $toClass): array { - return [ - $fromClass->getMethod($methodName), - $toClass->getMethod($methodName), - $errorMessages, - ]; - }, + static fn (string $methodName, array $errors): array => [ + $fromClass->getMethod($methodName), + $toClass->getMethod($methodName), + $errors, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/MethodBased/MethodVisibilityReducedTest.php b/test/unit/DetectChanges/BCBreak/MethodBased/MethodVisibilityReducedTest.php index a2298a82..1d69bd4b 100644 --- a/test/unit/DetectChanges/BCBreak/MethodBased/MethodVisibilityReducedTest.php +++ b/test/unit/DetectChanges/BCBreak/MethodBased/MethodVisibilityReducedTest.php @@ -111,14 +111,11 @@ public function privateIncreasedToPublic() {} return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $method, array $errorMessages) use ($fromClass, $toClass): array { - return [ - $fromClass->getMethod($method), - $toClass->getMethod($method), - $errorMessages, - ]; - }, + static fn (string $methodName, array $errors): array => [ + $fromClass->getMethod($methodName), + $toClass->getMethod($methodName), + $errors, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyBecameInternalTest.php b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyBecameInternalTest.php index 37e79b9c..b6162a82 100644 --- a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyBecameInternalTest.php +++ b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyBecameInternalTest.php @@ -100,14 +100,11 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $property, array $errorMessages) use ($fromClass, $toClass): array { - return [ - TypeRestriction::object($fromClass->getProperty($property)), - TypeRestriction::object($toClass->getProperty($property)), - $errorMessages, - ]; - }, + static fn (string $property, array $errorMessages): array => [ + TypeRestriction::object($fromClass->getProperty($property)), + TypeRestriction::object($toClass->getProperty($property)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyDefaultValueChangedTest.php b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyDefaultValueChangedTest.php index bf65aabd..9e09d8a2 100644 --- a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyDefaultValueChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyDefaultValueChangedTest.php @@ -142,14 +142,11 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $property, array $errorMessages) use ($fromClass, $toClass): array { - return [ - TypeRestriction::object($fromClass->getProperty($property)), - TypeRestriction::object($toClass->getProperty($property)), - $errorMessages, - ]; - }, + static fn (string $property, array $errorMessages): array => [ + TypeRestriction::object($fromClass->getProperty($property)), + TypeRestriction::object($toClass->getProperty($property)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyScopeChangedTest.php b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyScopeChangedTest.php index b9a80346..ced1d786 100644 --- a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyScopeChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyScopeChangedTest.php @@ -126,14 +126,11 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $property, array $errorMessages) use ($fromClass, $toClass): array { - return [ - TypeRestriction::object($fromClass->getProperty($property)), - TypeRestriction::object($toClass->getProperty($property)), - $errorMessages, - ]; - }, + static fn (string $property, array $errorMessages): array => [ + TypeRestriction::object($fromClass->getProperty($property)), + TypeRestriction::object($toClass->getProperty($property)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyTypeChangedTest.php b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyTypeChangedTest.php index a2ea72c1..7024d24f 100644 --- a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyTypeChangedTest.php +++ b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyTypeChangedTest.php @@ -242,14 +242,11 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $property, array $errorMessages) use ($fromClass, $toClass): array { - return [ - TypeRestriction::object($fromClass->getProperty($property)), - TypeRestriction::object($toClass->getProperty($property)), - $errorMessages, - ]; - }, + static fn (string $property, array $errorMessages): array => [ + TypeRestriction::object($fromClass->getProperty($property)), + TypeRestriction::object($toClass->getProperty($property)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyVisibilityReducedTest.php b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyVisibilityReducedTest.php index 76a49145..f9a5560b 100644 --- a/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyVisibilityReducedTest.php +++ b/test/unit/DetectChanges/BCBreak/PropertyBased/PropertyVisibilityReducedTest.php @@ -111,14 +111,11 @@ class TheClass { return array_combine( array_keys($properties), array_map( - /** @psalm-param list $errorMessages https://github.com/vimeo/psalm/issues/2772 */ - static function (string $property, array $errorMessages) use ($fromClass, $toClass): array { - return [ - TypeRestriction::object($fromClass->getProperty($property)), - TypeRestriction::object($toClass->getProperty($property)), - $errorMessages, - ]; - }, + static fn (string $property, array $errorMessages): array => [ + TypeRestriction::object($fromClass->getProperty($property)), + TypeRestriction::object($toClass->getProperty($property)), + $errorMessages, + ], array_keys($properties), $properties ) diff --git a/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameClassTest.php b/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameClassTest.php index 0fd0d601..37cae936 100644 --- a/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameClassTest.php +++ b/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameClassTest.php @@ -93,14 +93,11 @@ interface InterfaceToInterface {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameInterfaceTest.php b/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameInterfaceTest.php index bb90af1c..f1f25528 100644 --- a/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameInterfaceTest.php +++ b/test/unit/DetectChanges/BCBreak/TraitBased/TraitBecameInterfaceTest.php @@ -93,14 +93,11 @@ interface InterfaceToInterface {} return array_combine( array_keys($classes), array_map( - /** @psalm-param list $errors https://github.com/vimeo/psalm/issues/2772 */ - static function (string $className, array $errors) use ($fromReflector, $toReflector): array { - return [ - $fromReflector->reflectClass($className), - $toReflector->reflectClass($className), - $errors, - ]; - }, + static fn (string $className, array $errors): array => [ + $fromReflector->reflectClass($className), + $toReflector->reflectClass($className), + $errors, + ], array_keys($classes), $classes ) diff --git a/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php b/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php index 0c8473db..17f4af2c 100644 --- a/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php +++ b/test/unit/DetectChanges/Variance/TypeIsContravariantTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\TestCase; use Psl\Type; use Roave\BackwardCompatibility\DetectChanges\Variance\TypeIsContravariant; -use Roave\BackwardCompatibility\DetectChanges\Variance\TypeWithReflectorScope; use Roave\BetterReflection\BetterReflection; use Roave\BetterReflection\Reflection\ReflectionProperty; use Roave\BetterReflection\Reflection\ReflectionType; @@ -290,7 +289,7 @@ final class OwnerPropertyContainer { private $owner; } */ public function testContravarianceConsidersNullability(string $type): void { - $reflector = new DefaultReflector(new StringSourceLocator( + $reflector = new DefaultReflector(new StringSourceLocator( <<<'PHP'