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 use PHP 8.1 syntax #89

Merged
merged 1 commit into from
Nov 22, 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
72 changes: 34 additions & 38 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<InternalMethod>
<code><![CDATA[getComparisonFailure]]></code>
</InternalMethod>
<MixedArgument>
<code><![CDATA[$controllerManager->get($controllerIdentifier)]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$controllerIdentifier]]></code>
<code><![CDATA[$controllerManager]]></code>
Expand Down Expand Up @@ -426,31 +423,21 @@
</file>
<file src="test/PHPUnit/Util/ModuleLoaderTest.php">
<ArgumentTypeCoercion>
<code><![CDATA['Baz\Module']]></code>
<code><![CDATA['Baz\Module']]></code>
<code><![CDATA['Baz\Module']]></code>
<code><![CDATA['Baz\Module']]></code>
<code><![CDATA['Foo\Module']]></code>
<code><![CDATA['ModuleWithNamespace\TestModule\Module']]></code>
<code><![CDATA['stdClass']]></code>
</ArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$baz]]></code>
<code><![CDATA[$baz]]></code>
<code><![CDATA[$baz]]></code>
<code><![CDATA[$baz]]></code>
<code><![CDATA[$file]]></code>
<code><![CDATA[$foo]]></code>
<code><![CDATA[$fooObject]]></code>
</MixedAssignment>
<PossiblyUnusedReturnValue>
<code><![CDATA[bool]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="test/_files/Baz/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[getAutoloaderConfig]]></code>
<code><![CDATA[getConfig]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/Baz/src/Baz/Controller/IndexController.php">
<MixedAssignment>
Expand All @@ -468,6 +455,16 @@
<code><![CDATA[['num_get' => $numGet, 'num_post' => $numPost]]]></code>
<code><![CDATA[array<string, string>]]></code>
</MixedReturnTypeCoercion>
<PossiblyUnusedMethod>
<code><![CDATA[childViewAction]]></code>
<code><![CDATA[customResponseAction]]></code>
<code><![CDATA[exceptionAction]]></code>
<code><![CDATA[persistencetestAction]]></code>
<code><![CDATA[redirectAction]]></code>
<code><![CDATA[redirectToRouteAction]]></code>
<code><![CDATA[registerxpathnamespaceAction]]></code>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
<UndefinedInterfaceMethod>
<code><![CDATA[getHeaders]]></code>
<code><![CDATA[getPost]]></code>
Expand All @@ -476,9 +473,6 @@
<UndefinedMagicMethod>
<code><![CDATA[flashMessenger]]></code>
</UndefinedMagicMethod>
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
</file>
<file src="test/_files/ModuleWithEvents/Module.php">
<MissingClosureParamType>
Expand All @@ -502,48 +496,50 @@
</PossiblyUnusedMethod>
</file>
<file src="test/_files/ModuleWithNamespace/TestModule/src/Controller/IndexController.php">
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/ModuleWithSimilarName/Test/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
</file>
<file src="test/_files/ModuleWithSimilarName/Test/src/Controller/IndexController.php">
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/ModuleWithSimilarName/TestModule/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
</file>
<file src="test/_files/ModuleWithSimilarName/TestModule/src/Controller/IndexController.php">
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/modules-path/with-subdir/Bar/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
</file>
<file src="test/_files/modules-path/with-subdir/Bar/src/Bar/Controller/IndexController.php">
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/modules-path/with-subdir/Foo/Module.php">
<UnusedClass>
<code><![CDATA[Module]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[getAutoloaderConfig]]></code>
<code><![CDATA[getConfig]]></code>
<code><![CDATA[getServiceConfig]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/_files/modules-path/with-subdir/Foo/src/Foo/Controller/IndexController.php">
<UnusedClass>
<code><![CDATA[IndexController]]></code>
</UnusedClass>
<PossiblyUnusedMethod>
<code><![CDATA[unittestsAction]]></code>
</PossiblyUnusedMethod>
</file>
</files>
5 changes: 1 addition & 4 deletions src/PHPUnit/Constraint/HasRedirectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/PHPUnit/Constraint/IsCurrentModuleNameConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions src/PHPUnit/Constraint/IsRedirectedRouteNameConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
));
}

Expand Down
3 changes: 1 addition & 2 deletions src/PHPUnit/Constraint/LaminasConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use SebastianBergmann\Comparator\ComparisonFailure;
use Throwable;

use function get_class;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -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;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/PHPUnit/Controller/AbstractControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -497,7 +496,7 @@ public function assertApplicationException($type, $message = null)
*/
protected function getControllerFullClassName()
{
return get_class($this->getControllerFullClass());
return $this->getControllerFullClass()::class;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions test/PHPUnit/Util/ModuleLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
}

Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion test/_files/Baz/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Baz\Controller\IndexController;

return [
'router' => [
'routes' => [
Expand Down Expand Up @@ -122,7 +124,7 @@
],
'controllers' => [
'invokables' => [
'baz_index' => 'Baz\Controller\IndexController',
'baz_index' => IndexController::class,
],
],
'view_manager' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use ModuleWithNamespace\TestModule\Controller\IndexController;

return [
'router' => [
'routes' => [
Expand All @@ -19,7 +21,7 @@
],
'controllers' => [
'invokables' => [
'namespace_index' => 'ModuleWithNamespace\TestModule\Controller\IndexController',
'namespace_index' => IndexController::class,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use ModuleWithSimilarName\Test\Controller\IndexController;

return [
'router' => [
'routes' => [
Expand All @@ -19,7 +21,7 @@
],
'controllers' => [
'invokables' => [
'similar_name_index' => 'ModuleWithSimilarName\Test\Controller\IndexController',
'similar_name_index' => IndexController::class,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use ModuleWithSimilarName\TestModule\Controller\IndexController;

return [
'router' => [
'routes' => [
Expand All @@ -19,7 +21,7 @@
],
'controllers' => [
'invokables' => [
'similar_name_2_index' => 'ModuleWithSimilarName\TestModule\Controller\IndexController',
'similar_name_2_index' => IndexController::class,
],
],
];
Loading