From ce5d1dd042288d863542d42183cbdf20f9880bd2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 12 Oct 2026 10:26:18 +0700 Subject: [PATCH] Use StructArmed on QA Signed-off-by: Abdul Malik Ikhsan --- composer.json | 9 ++++---- src/App/src/DBAL/Types/AbstractEnumType.php | 2 +- .../src/Factory/PluginManagerFactory.php | 4 ++-- src/User/src/Entity/User.php | 2 +- src/User/src/Entity/UserIdentity.php | 2 +- structarmed.php | 21 +++++++++++++++++++ test/Unit/Plugin/FormsPluginTest.php | 2 +- 7 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 structarmed.php diff --git a/composer.json b/composer.json index 428e9c3f..3dc4216f 100644 --- a/composer.json +++ b/composer.json @@ -73,17 +73,18 @@ "roave/psr-container-doctrine": "^5.2.2" }, "require-dev": { + "boundwize/structarmed": "^0.19.4", "filp/whoops": "^2.15.4", "laminas/laminas-coding-standard": "^3.0", "laminas/laminas-development-mode": "^3.12.0", "mezzio/mezzio-tooling": "^2.9.0", - "phpunit/phpunit": "^10.5", - "roave/security-advisories": "dev-master", - "vincentlanglet/twig-cs-fixer": "^2.12", "phpstan/phpstan": "^2.0", "phpstan/phpstan-doctrine": "^2.0", "phpstan/phpstan-phpunit": "^2.0", - "symfony/var-dumper": "^7.1" + "phpunit/phpunit": "^10.5", + "roave/security-advisories": "dev-master", + "symfony/var-dumper": "^7.1", + "vincentlanglet/twig-cs-fixer": "^2.12" }, "autoload": { "psr-4": { diff --git a/src/App/src/DBAL/Types/AbstractEnumType.php b/src/App/src/DBAL/Types/AbstractEnumType.php index d6517774..f7d7a6d3 100644 --- a/src/App/src/DBAL/Types/AbstractEnumType.php +++ b/src/App/src/DBAL/Types/AbstractEnumType.php @@ -24,7 +24,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return 'TEXT'; } - $values = array_map(fn($case) => "'{$case->value}'", $this->getEnumValues()); + $values = array_map(static fn($case) => "'{$case->value}'", $this->getEnumValues()); return sprintf('ENUM(%s)', implode(', ', $values)); } diff --git a/src/Plugin/src/Factory/PluginManagerFactory.php b/src/Plugin/src/Factory/PluginManagerFactory.php index 0332bcdc..524ce005 100644 --- a/src/Plugin/src/Factory/PluginManagerFactory.php +++ b/src/Plugin/src/Factory/PluginManagerFactory.php @@ -25,13 +25,13 @@ public function __invoke(ContainerInterface $container): PluginManager //register the built-in plugins, if the required component is present if ($container->has(UrlHelper::class)) { - $pluginManager->setFactory('url', function (ContainerInterface $container) { + $pluginManager->setFactory('url', static function (ContainerInterface $container) { return new UrlHelperPlugin($container->get(UrlHelper::class)); }); } if ($container->has(TemplateRendererInterface::class)) { - $pluginManager->setFactory('template', function (ContainerInterface $container) { + $pluginManager->setFactory('template', static function (ContainerInterface $container) { return new TemplatePlugin($container->get(TemplateRendererInterface::class)); }); } diff --git a/src/User/src/Entity/User.php b/src/User/src/Entity/User.php index cd04414f..3a9fda58 100644 --- a/src/User/src/Entity/User.php +++ b/src/User/src/Entity/User.php @@ -276,7 +276,7 @@ public function getArrayCopy(): array 'avatar' => $this->getAvatar()?->getArrayCopy(), 'identity' => $this->getIdentity(), 'status' => $this->getStatus(), - 'roles' => $this->getRoles()->map(function (UserRole $userRole) { + 'roles' => $this->getRoles()->map(static function (UserRole $userRole) { return $userRole->getArrayCopy(); })->toArray(), 'created' => $this->getCreated(), diff --git a/src/User/src/Entity/UserIdentity.php b/src/User/src/Entity/UserIdentity.php index bb430ae9..7621fd90 100644 --- a/src/User/src/Entity/UserIdentity.php +++ b/src/User/src/Entity/UserIdentity.php @@ -53,7 +53,7 @@ public static function fromEntity(UserIdentityInterface $user): self return new self( $user->getUuid()->toString(), $user->getIdentity(), - $user->getRoles()->map(function (UserRole $userRole) { + $user->getRoles()->map(static function (UserRole $userRole) { return $userRole->getName(); })->toArray(), $user->getDetail()->getArrayCopy(), diff --git a/structarmed.php b/structarmed.php new file mode 100644 index 00000000..f9d54d4c --- /dev/null +++ b/structarmed.php @@ -0,0 +1,21 @@ +withPresets(Preset::PSR4(), Preset::CODEQUALITY()) + ->layer('Plugin', 'src/Plugin/src') + ->layer('App', 'src/App/src') + ->layer('User', 'src/User/src') + ->layer('Contact', 'src/Contact/src') + ->layer('Page', 'src/Page/src') + ->ruleset([ + 'Plugin' => [], + 'App' => ['User'], + 'User' => ['+App', 'Plugin'], + 'Contact' => ['+User'], + 'Page' => [], + ]); diff --git a/test/Unit/Plugin/FormsPluginTest.php b/test/Unit/Plugin/FormsPluginTest.php index 1fbc1361..cf6f52af 100644 --- a/test/Unit/Plugin/FormsPluginTest.php +++ b/test/Unit/Plugin/FormsPluginTest.php @@ -62,7 +62,7 @@ public function testWillRestoreState(): void ->expects($this->exactly(2)) ->method('getData') ->willReturnCallback( - function (string $key) use ($newData, $newMessages) { + static function (string $key) use ($newData, $newMessages) { return match ($key) { 'loginForm_data' => $newData, 'loginForm_messages' => $newMessages,