diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 92c954ff..2c547b0d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -9,9 +9,6 @@ - - get($controllerIdentifier)]]> - @@ -426,21 +423,10 @@ - - - - - - - - - - - @@ -448,9 +434,10 @@ - - - + + + + @@ -468,6 +455,16 @@ $numGet, 'num_post' => $numPost]]]> ]]> + + + + + + + + + + @@ -476,9 +473,6 @@ - - - @@ -502,9 +496,9 @@ - - - + + + @@ -512,9 +506,9 @@ - - - + + + @@ -522,9 +516,9 @@ - - - + + + @@ -532,18 +526,20 @@ - - - + + + - - - + + + + + - - - + + + diff --git a/src/PHPUnit/Constraint/HasRedirectConstraint.php b/src/PHPUnit/Constraint/HasRedirectConstraint.php index 5c12fa6c..451e1af9 100644 --- a/src/PHPUnit/Constraint/HasRedirectConstraint.php +++ b/src/PHPUnit/Constraint/HasRedirectConstraint.php @@ -11,11 +11,8 @@ final class HasRedirectConstraint extends Constraint { - private AbstractHttpControllerTestCase $activeTestCase; - - public function __construct(AbstractHttpControllerTestCase $activeTestCase) + public function __construct(private readonly AbstractHttpControllerTestCase $activeTestCase) { - $this->activeTestCase = $activeTestCase; } public function toString(): string diff --git a/src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php b/src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php index f013ea15..14400f16 100644 --- a/src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php +++ b/src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php @@ -5,7 +5,7 @@ namespace Laminas\Test\PHPUnit\Constraint; use function ltrim; -use function strpos; +use function str_contains; use function strrpos; use function strtolower; use function substr; @@ -41,8 +41,8 @@ public function getCurrentModuleName(): string // Find Module from Controller /** @var string $appModules */ foreach ($applicationConfig['modules'] as $appModules) { - if (strpos($controllerClass, $appModules . '\\') !== false) { - if (strpos($appModules, '\\') !== false) { + if (str_contains($controllerClass, $appModules . '\\')) { + if (str_contains($appModules, '\\')) { $match = ltrim(substr($appModules, strrpos($appModules, '\\')), '\\'); } else { $match = ltrim($appModules); diff --git a/src/PHPUnit/Constraint/IsRedirectedRouteNameConstraint.php b/src/PHPUnit/Constraint/IsRedirectedRouteNameConstraint.php index a5bb0ed4..3aa6aa8d 100644 --- a/src/PHPUnit/Constraint/IsRedirectedRouteNameConstraint.php +++ b/src/PHPUnit/Constraint/IsRedirectedRouteNameConstraint.php @@ -15,18 +15,14 @@ use PHPUnit\Framework\Constraint\Constraint; use RuntimeException; -use function gettype; -use function is_object; +use function get_debug_type; use function is_string; use function sprintf; final class IsRedirectedRouteNameConstraint extends Constraint { - private AbstractHttpControllerTestCase $activeTestCase; - - public function __construct(AbstractHttpControllerTestCase $activeTestCase) + public function __construct(private readonly AbstractHttpControllerTestCase $activeTestCase) { - $this->activeTestCase = $activeTestCase; } public function toString(): string @@ -91,7 +87,7 @@ private function getControllerFullClass(): AbstractController throw new RuntimeException(sprintf( 'Invalid controller pulled from ControllerManager by identifier "%s"; received "%s"', $controllerIdentifier, - is_object($controller) ? $controller::class : gettype($controller) + get_debug_type($controller) )); } diff --git a/src/PHPUnit/Constraint/LaminasConstraint.php b/src/PHPUnit/Constraint/LaminasConstraint.php index 74d8bbe9..ef308ca6 100644 --- a/src/PHPUnit/Constraint/LaminasConstraint.php +++ b/src/PHPUnit/Constraint/LaminasConstraint.php @@ -11,7 +11,6 @@ use SebastianBergmann\Comparator\ComparisonFailure; use Throwable; -use function get_class; use function implode; use function sprintf; @@ -53,7 +52,7 @@ final public function getControllerFullClassName(): string $controllerManager = $this->activeTestCase->getApplicationServiceLocator()->get('ControllerManager'); - return get_class($controllerManager->get($controllerIdentifier)); + return $controllerManager->get($controllerIdentifier)::class; } /** diff --git a/src/PHPUnit/Controller/AbstractControllerTestCase.php b/src/PHPUnit/Controller/AbstractControllerTestCase.php index 60e2b5db..484294c5 100644 --- a/src/PHPUnit/Controller/AbstractControllerTestCase.php +++ b/src/PHPUnit/Controller/AbstractControllerTestCase.php @@ -36,7 +36,6 @@ use function assert; use function class_exists; use function count; -use function get_class; use function http_build_query; use function implode; use function method_exists; @@ -497,7 +496,7 @@ public function assertApplicationException($type, $message = null) */ protected function getControllerFullClassName() { - return get_class($this->getControllerFullClass()); + return $this->getControllerFullClass()::class; } /** diff --git a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php index ac75e765..6f64f69f 100644 --- a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php @@ -24,7 +24,6 @@ use function array_merge_recursive; use function count; use function extension_loaded; -use function get_class; use function glob; use function is_dir; use function method_exists; @@ -106,14 +105,14 @@ public function testCanNotDefineApplicationConfigWhenApplicationIsBuilt() /** @return void */ public function testApplicationClass() { - $applicationClass = get_class($this->getApplication()); + $applicationClass = $this->getApplication()::class; $this->assertEquals($applicationClass, Application::class); } /** @return void */ public function testApplicationServiceLocatorClass() { - $smClass = get_class($this->getApplicationServiceLocator()); + $smClass = $this->getApplicationServiceLocator()::class; $this->assertEquals($smClass, ServiceManager::class); } diff --git a/test/PHPUnit/Util/ModuleLoaderTest.php b/test/PHPUnit/Util/ModuleLoaderTest.php index d740206b..61eff4f6 100644 --- a/test/PHPUnit/Util/ModuleLoaderTest.php +++ b/test/PHPUnit/Util/ModuleLoaderTest.php @@ -61,7 +61,7 @@ public function testCanLoadModule() $loader = new ModuleLoader(['Baz']); $baz = $loader->getModule('Baz'); - $this->assertInstanceOf('Baz\Module', $baz); + $this->assertInstanceOf(\Baz\Module::class, $baz); } /** @return void */ @@ -73,7 +73,7 @@ public function testCanLoadModuleWithNamespace() $testModule = $loader->getModule('ModuleWithNamespace\TestModule'); - $this->assertInstanceOf('ModuleWithNamespace\TestModule\Module', $testModule); + $this->assertInstanceOf(Module::class, $testModule); $this->assertInstanceOf(Module::class, $testModule); } @@ -89,7 +89,7 @@ public function testCanLoadModuleWithPath() { $loader = new ModuleLoader(['Baz' => __DIR__ . '/../../_files/Baz']); $baz = $loader->getModule('Baz'); - $this->assertInstanceOf('Baz\Module', $baz); + $this->assertInstanceOf(\Baz\Module::class, $baz); } /** @return void */ @@ -100,9 +100,9 @@ public function testCanLoadModules() $loader = new ModuleLoader(['Baz', 'Foo']); $baz = $loader->getModule('Baz'); - $this->assertInstanceOf('Baz\Module', $baz); + $this->assertInstanceOf(\Baz\Module::class, $baz); $foo = $loader->getModule('Foo'); - $this->assertInstanceOf('Foo\Module', $foo); + $this->assertInstanceOf(\Foo\Module::class, $foo); } /** @return void */ @@ -123,7 +123,7 @@ public function testCanLoadModulesFromConfig() $config = include __DIR__ . '/../../_files/application.config.php'; $loader = new ModuleLoader($config); $baz = $loader->getModule('Baz'); - $this->assertInstanceOf('Baz\Module', $baz); + $this->assertInstanceOf(\Baz\Module::class, $baz); } /** @return void */ diff --git a/test/_files/Baz/config/module.config.php b/test/_files/Baz/config/module.config.php index f1f1889d..167e7d02 100644 --- a/test/_files/Baz/config/module.config.php +++ b/test/_files/Baz/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Baz\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -122,7 +124,7 @@ ], 'controllers' => [ 'invokables' => [ - 'baz_index' => 'Baz\Controller\IndexController', + 'baz_index' => IndexController::class, ], ], 'view_manager' => [ diff --git a/test/_files/ModuleWithNamespace/TestModule/config/module.config.php b/test/_files/ModuleWithNamespace/TestModule/config/module.config.php index d9576dd6..623bc8b7 100644 --- a/test/_files/ModuleWithNamespace/TestModule/config/module.config.php +++ b/test/_files/ModuleWithNamespace/TestModule/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use ModuleWithNamespace\TestModule\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -19,7 +21,7 @@ ], 'controllers' => [ 'invokables' => [ - 'namespace_index' => 'ModuleWithNamespace\TestModule\Controller\IndexController', + 'namespace_index' => IndexController::class, ], ], ]; diff --git a/test/_files/ModuleWithSimilarName/Test/config/module.config.php b/test/_files/ModuleWithSimilarName/Test/config/module.config.php index 06550f72..c7884c54 100644 --- a/test/_files/ModuleWithSimilarName/Test/config/module.config.php +++ b/test/_files/ModuleWithSimilarName/Test/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use ModuleWithSimilarName\Test\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -19,7 +21,7 @@ ], 'controllers' => [ 'invokables' => [ - 'similar_name_index' => 'ModuleWithSimilarName\Test\Controller\IndexController', + 'similar_name_index' => IndexController::class, ], ], ]; diff --git a/test/_files/ModuleWithSimilarName/TestModule/config/module.config.php b/test/_files/ModuleWithSimilarName/TestModule/config/module.config.php index bd849b26..5ffb6e8d 100644 --- a/test/_files/ModuleWithSimilarName/TestModule/config/module.config.php +++ b/test/_files/ModuleWithSimilarName/TestModule/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use ModuleWithSimilarName\TestModule\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -19,7 +21,7 @@ ], 'controllers' => [ 'invokables' => [ - 'similar_name_2_index' => 'ModuleWithSimilarName\TestModule\Controller\IndexController', + 'similar_name_2_index' => IndexController::class, ], ], ]; diff --git a/test/_files/modules-path/with-subdir/Bar/config/module.config.php b/test/_files/modules-path/with-subdir/Bar/config/module.config.php index 0f3dc6ac..fb3c2394 100644 --- a/test/_files/modules-path/with-subdir/Bar/config/module.config.php +++ b/test/_files/modules-path/with-subdir/Bar/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Bar\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -19,7 +21,7 @@ ], 'controllers' => [ 'invokables' => [ - 'bar_index' => 'Bar\Controller\IndexController', + 'bar_index' => IndexController::class, ], ], 'view_manager' => [ diff --git a/test/_files/modules-path/with-subdir/Foo/config/module.config.php b/test/_files/modules-path/with-subdir/Foo/config/module.config.php index 3e2da11b..1eaf687f 100644 --- a/test/_files/modules-path/with-subdir/Foo/config/module.config.php +++ b/test/_files/modules-path/with-subdir/Foo/config/module.config.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Foo\Controller\IndexController; + return [ 'router' => [ 'routes' => [ @@ -19,7 +21,7 @@ ], 'controllers' => [ 'invokables' => [ - 'foo_index' => 'Foo\Controller\IndexController', + 'foo_index' => IndexController::class, ], ], 'view_manager' => [