From 0eb04dfbe0959b59070c00c8222d5a8f4a951cb7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 25 Sep 2026 13:37:39 +0700 Subject: [PATCH] Use StructArmed on QA Signed-off-by: Abdul Malik Ikhsan --- composer.json | 1 + .../src/Adapter/AuthenticationAdapter.php | 2 +- .../src/Delegator/AdminRoleDelegator.php | 2 +- .../Handler/Admin/GetEditAdminFormHandler.php | 2 +- .../Handler/Admin/PostEditAdminHandler.php | 2 +- src/Core/src/Admin/src/Entity/Admin.php | 2 +- .../src/Admin/src/Enum/AdminStatusEnum.php | 2 +- .../App/src/DBAL/Types/AbstractEnumType.php | 2 +- src/Core/src/User/src/Entity/User.php | 2 +- src/Core/src/User/src/Enum/UserRoleEnum.php | 2 +- src/Core/src/User/src/Enum/UserStatusEnum.php | 4 +-- src/User/src/Delegator/UserRoleDelegator.php | 4 +-- .../src/Handler/GetEditUserFormHandler.php | 4 +-- .../src/Handler/PostEditUserAvatarHandler.php | 4 +-- src/User/src/Handler/PostEditUserHandler.php | 4 +-- structarmed.php | 35 +++++++++++++++++++ .../Delegator/AdminRoleDelegatorTest.php | 4 +-- test/Unit/App/Plugin/FormsPluginTest.php | 2 +- 18 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 structarmed.php diff --git a/composer.json b/composer.json index 5f84f1b5..478cb3c1 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,7 @@ "symfony/var-exporter": "^6.4 || ^7.4" }, "require-dev": { + "boundwize/structarmed": "^0.18.0", "dotkernel/dot-maker": "^2.0.0", "filp/whoops": "^2.18.4", "laminas/laminas-coding-standard": "^3.1.0", diff --git a/src/Admin/src/Adapter/AuthenticationAdapter.php b/src/Admin/src/Adapter/AuthenticationAdapter.php index b1ab6bfb..ed3c51e9 100644 --- a/src/Admin/src/Adapter/AuthenticationAdapter.php +++ b/src/Admin/src/Adapter/AuthenticationAdapter.php @@ -142,7 +142,7 @@ public function authenticate(): Result /** @var non-empty-string[] $roles */ $roles = array_map( - fn (RoleInterface $role): string => (string) $role->getName()->value, + static fn (RoleInterface $role): string => (string) $role->getName()->value, $identityClass->getRoles() ); diff --git a/src/Admin/src/Delegator/AdminRoleDelegator.php b/src/Admin/src/Delegator/AdminRoleDelegator.php index 3b52fac9..eadc99d2 100644 --- a/src/Admin/src/Delegator/AdminRoleDelegator.php +++ b/src/Admin/src/Delegator/AdminRoleDelegator.php @@ -28,7 +28,7 @@ public function __invoke(ContainerInterface $container, $name, callable $callbac $adminForm = $callback(); if ($adminForm instanceof CreateAdminForm) { $adminForm->setRoles( - array_map(fn (AdminRole $role): array => [ + array_map(static fn (AdminRole $role): array => [ 'label' => $role->getName()->value, 'value' => $role->getId()->toString(), 'selected' => false, diff --git a/src/Admin/src/Handler/Admin/GetEditAdminFormHandler.php b/src/Admin/src/Handler/Admin/GetEditAdminFormHandler.php index 6bcc0bbf..f061faf0 100644 --- a/src/Admin/src/Handler/Admin/GetEditAdminFormHandler.php +++ b/src/Admin/src/Handler/Admin/GetEditAdminFormHandler.php @@ -64,7 +64,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $adminRoles = $this->adminRoleService->getAdminRoleRepository()->findAll(); $adminRoles = array_map( /** @return SelectDataType */ - fn (AdminRole $adminRole): array => [ + static fn (AdminRole $adminRole): array => [ 'label' => $adminRole->getName()->value, 'value' => $adminRole->getId()->toString(), 'selected' => $admin->hasRole($adminRole), diff --git a/src/Admin/src/Handler/Admin/PostEditAdminHandler.php b/src/Admin/src/Handler/Admin/PostEditAdminHandler.php index 0feb25d8..32606294 100644 --- a/src/Admin/src/Handler/Admin/PostEditAdminHandler.php +++ b/src/Admin/src/Handler/Admin/PostEditAdminHandler.php @@ -73,7 +73,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $adminRoles = $this->adminRoleService->getAdminRoleRepository()->findAll(); $adminRoles = array_map( /** @return SelectDataType */ - fn (AdminRole $adminRole): array => [ + static fn (AdminRole $adminRole): array => [ 'label' => $adminRole->getName()->value, 'value' => $adminRole->getId()->toString(), 'selected' => $admin->hasRole($adminRole), diff --git a/src/Core/src/Admin/src/Entity/Admin.php b/src/Core/src/Admin/src/Entity/Admin.php index fde0af45..4bb7069b 100644 --- a/src/Core/src/Admin/src/Entity/Admin.php +++ b/src/Core/src/Admin/src/Entity/Admin.php @@ -241,7 +241,7 @@ public function getArrayCopy(): array 'firstName' => $this->firstName, 'lastName' => $this->lastName, 'status' => $this->status->value, - 'roles' => array_map(fn (RoleInterface $role): array => $role->getArrayCopy(), $this->roles->toArray()), + 'roles' => array_map(static fn (RoleInterface $role): array => $role->getArrayCopy(), $this->roles->toArray()), 'created' => $this->created, 'updated' => $this->updated, ]; diff --git a/src/Core/src/Admin/src/Enum/AdminStatusEnum.php b/src/Core/src/Admin/src/Enum/AdminStatusEnum.php index 9fd605a8..eb44b150 100644 --- a/src/Core/src/Admin/src/Enum/AdminStatusEnum.php +++ b/src/Core/src/Admin/src/Enum/AdminStatusEnum.php @@ -25,7 +25,7 @@ public static function values(): array */ public static function toArray(): array { - return array_reduce(self::cases(), function (array $collector, self $enum): array { + return array_reduce(self::cases(), static function (array $collector, self $enum): array { $collector[$enum->value] = $enum->name; return $collector; diff --git a/src/Core/src/App/src/DBAL/Types/AbstractEnumType.php b/src/Core/src/App/src/DBAL/Types/AbstractEnumType.php index 43836973..795f4b89 100644 --- a/src/Core/src/App/src/DBAL/Types/AbstractEnumType.php +++ b/src/Core/src/App/src/DBAL/Types/AbstractEnumType.php @@ -26,7 +26,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return 'TEXT'; } - $values = array_map(fn($case) => "'$case->value'", $this->getEnumCases()); + $values = array_map(static fn($case) => "'$case->value'", $this->getEnumCases()); return sprintf('ENUM(%s)', implode(', ', $values)); } diff --git a/src/Core/src/User/src/Entity/User.php b/src/Core/src/User/src/Entity/User.php index d6d98861..7b29190f 100644 --- a/src/Core/src/User/src/Entity/User.php +++ b/src/Core/src/User/src/Entity/User.php @@ -361,7 +361,7 @@ public function getArrayCopy(): array 'hash' => $this->hash, 'identity' => $this->identity, 'status' => $this->status->value, - 'roles' => array_map(fn (RoleInterface $role): array => $role->getArrayCopy(), $this->roles->toArray()), + 'roles' => array_map(static fn (RoleInterface $role): array => $role->getArrayCopy(), $this->roles->toArray()), 'created' => $this->created, 'updated' => $this->updated, ]; diff --git a/src/Core/src/User/src/Enum/UserRoleEnum.php b/src/Core/src/User/src/Enum/UserRoleEnum.php index b2d89bd5..80e91d94 100644 --- a/src/Core/src/User/src/Enum/UserRoleEnum.php +++ b/src/Core/src/User/src/Enum/UserRoleEnum.php @@ -17,7 +17,7 @@ enum UserRoleEnum: string */ public static function validCases(): array { - return array_filter(self::cases(), fn (self $value) => $value !== self::Guest); + return array_filter(self::cases(), static fn (self $value) => $value !== self::Guest); } /** diff --git a/src/Core/src/User/src/Enum/UserStatusEnum.php b/src/Core/src/User/src/Enum/UserStatusEnum.php index ecaa6960..8ab061ab 100644 --- a/src/Core/src/User/src/Enum/UserStatusEnum.php +++ b/src/Core/src/User/src/Enum/UserStatusEnum.php @@ -35,7 +35,7 @@ public static function validValues(): array */ public static function validCases(): array { - return array_filter(self::cases(), fn (self $enum) => $enum !== self::Deleted); + return array_filter(self::cases(), static fn (self $enum) => $enum !== self::Deleted); } /** @@ -43,7 +43,7 @@ public static function validCases(): array */ public static function toArray(): array { - return array_reduce(self::validCases(), function (array $collector, self $enum): array { + return array_reduce(self::validCases(), static function (array $collector, self $enum): array { $collector[$enum->value] = $enum->name; return $collector; diff --git a/src/User/src/Delegator/UserRoleDelegator.php b/src/User/src/Delegator/UserRoleDelegator.php index 24b8636c..590560f8 100644 --- a/src/User/src/Delegator/UserRoleDelegator.php +++ b/src/User/src/Delegator/UserRoleDelegator.php @@ -31,12 +31,12 @@ public function __invoke(ContainerInterface $container, $name, callable $callbac { $userForm = $callback(); if ($userForm instanceof CreateUserForm) { - $userRoles = array_map(fn (UserRole $role): array => [ + $userRoles = array_map(static fn (UserRole $role): array => [ 'label' => $role->getName()->value, 'value' => $role->getId()->toString(), 'selected' => $role->getName() === self::DEFAULT_ROLE, ], $container->get(EntityManagerInterface::class)->getRepository(UserRole::class)->findAll()); - $userRoles = array_filter($userRoles, fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); + $userRoles = array_filter($userRoles, static fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); $userForm->setRoles($userRoles); } diff --git a/src/User/src/Handler/GetEditUserFormHandler.php b/src/User/src/Handler/GetEditUserFormHandler.php index 26e531fa..b3ef3018 100644 --- a/src/User/src/Handler/GetEditUserFormHandler.php +++ b/src/User/src/Handler/GetEditUserFormHandler.php @@ -69,14 +69,14 @@ public function handle(ServerRequestInterface $request): ResponseInterface $userRoles = $this->userRoleService->getUserRoleRepository()->findAll(); $userRoles = array_map( /** @return SelectDataType */ - fn (UserRole $userRole): array => [ + static fn (UserRole $userRole): array => [ 'label' => $userRole->getName()->value, 'value' => $userRole->getId()->toString(), 'selected' => $user->hasRole($userRole), ], $userRoles ); - $userRoles = array_filter($userRoles, fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); + $userRoles = array_filter($userRoles, static fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); $this->editUserAvatarForm ->setAttribute( diff --git a/src/User/src/Handler/PostEditUserAvatarHandler.php b/src/User/src/Handler/PostEditUserAvatarHandler.php index f720b1e0..21643f83 100644 --- a/src/User/src/Handler/PostEditUserAvatarHandler.php +++ b/src/User/src/Handler/PostEditUserAvatarHandler.php @@ -78,14 +78,14 @@ public function handle(ServerRequestInterface $request): ResponseInterface $userRoles = $this->userRoleService->getUserRoleRepository()->findAll(); $userRoles = array_map( /** @return SelectDataType */ - fn (UserRole $userRole): array => [ + static fn (UserRole $userRole): array => [ 'label' => $userRole->getName()->value, 'value' => $userRole->getId()->toString(), 'selected' => $user->hasRole($userRole), ], $userRoles ); - $userRoles = array_filter($userRoles, fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); + $userRoles = array_filter($userRoles, static fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); $this->editUserAvatarForm ->setAttribute( diff --git a/src/User/src/Handler/PostEditUserHandler.php b/src/User/src/Handler/PostEditUserHandler.php index 51cc4f56..adf65ffb 100644 --- a/src/User/src/Handler/PostEditUserHandler.php +++ b/src/User/src/Handler/PostEditUserHandler.php @@ -78,14 +78,14 @@ public function handle(ServerRequestInterface $request): ResponseInterface $userRoles = $this->userRoleService->getUserRoleRepository()->findAll(); $userRoles = array_map( /** @return SelectDataType */ - fn (UserRole $userRole): array => [ + static fn (UserRole $userRole): array => [ 'label' => $userRole->getName()->value, 'value' => $userRole->getId()->toString(), 'selected' => $user->hasRole($userRole), ], $userRoles ); - $userRoles = array_filter($userRoles, fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); + $userRoles = array_filter($userRoles, static fn (array $role) => $role['label'] !== UserRoleEnum::Guest->value); $this->editUserAvatarForm ->setAttribute( diff --git a/structarmed.php b/structarmed.php new file mode 100644 index 00000000..0a6470a3 --- /dev/null +++ b/structarmed.php @@ -0,0 +1,35 @@ +withPresets(Preset::PSR4(), Preset::CODEQUALITY()) + ->layer('CoreApp', 'src/Core/src/App/src', 'src/Core/src/App/src/Fixture') + ->layer('CoreFixture', 'src/Core/src/App/src/Fixture') + ->layer('CoreSetting', 'src/Core/src/Setting/src') + ->layer('CoreAdmin', 'src/Core/src/Admin/src') + ->layer('CoreSecurity', 'src/Core/src/Security/src') + ->layer('CoreUser', 'src/Core/src/User/src') + ->layer('App', 'src/App/src') + ->layer('Admin', 'src/Admin/src') + ->layer('Dashboard', 'src/Dashboard/src') + ->layer('Page', 'src/Page/src') + ->layer('Setting', 'src/Setting/src') + ->layer('User', 'src/User/src') + ->ruleset([ + 'CoreApp' => ['CoreUser'], + 'CoreSetting' => ['+CoreApp', 'CoreAdmin'], + 'CoreAdmin' => ['+CoreSetting'], + 'CoreSecurity' => ['+CoreAdmin'], + 'CoreUser' => ['+CoreSecurity'], + 'CoreFixture' => ['+CoreUser'], + 'App' => ['+CoreUser'], + 'Admin' => ['+App'], + 'Dashboard' => ['+App'], + 'Page' => ['+App'], + 'Setting' => ['+Admin'], + 'User' => ['+App'], + ]); diff --git a/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php b/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php index 7f309788..acf42465 100644 --- a/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php +++ b/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php @@ -28,7 +28,7 @@ public function testInvokeWillSucceedWithoutAdminForm(): void $delegator = (new AdminRoleDelegator())( $container, '', - fn () => new stdClass() + static fn () => new stdClass() ); $this->assertIsObject($delegator); @@ -53,7 +53,7 @@ public function testInvokeWillSucceedWithAdminForm(): void $delegator = (new AdminRoleDelegator())( $container, '', - fn () => new CreateAdminForm() + static fn () => new CreateAdminForm() ); $this->assertInstanceOf(CreateAdminForm::class, $delegator); diff --git a/test/Unit/App/Plugin/FormsPluginTest.php b/test/Unit/App/Plugin/FormsPluginTest.php index 36ea0216..b4444fb4 100644 --- a/test/Unit/App/Plugin/FormsPluginTest.php +++ b/test/Unit/App/Plugin/FormsPluginTest.php @@ -52,7 +52,7 @@ public function testWillRestoreState(): void ->expects($this->exactly(2)) ->method('getData') ->willReturnCallback( - fn (string $key) => match ($key) { + static fn (string $key) => match ($key) { 'loginForm_data' => $oldData, 'loginForm_messages' => [], default => null,