diff --git a/composer.json b/composer.json index f15c939..7250728 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "php": "~8.3.0 || ~8.4.0 || ~8.5.0" }, "require-dev": { + "boundwize/structarmed": "^0.19", "laminas/laminas-coding-standard": "^3.1.0", "mikey179/vfsstream": "^1.6.12", "phpstan/phpstan": "^2.1.33", diff --git a/src/Component/ClassFile.php b/src/Component/ClassFile.php index 409fdd2..b14b4fa 100644 --- a/src/Component/ClassFile.php +++ b/src/Component/ClassFile.php @@ -235,14 +235,14 @@ public function render(): string $class .= '{' . PHP_EOL; if (count($this->traits) > 0) { - $traits = array_map(fn (string $trait): string => $trait, $this->traits); + $traits = array_map(static fn (string $trait): string => $trait, $this->traits); $class .= ' ' . implode(PHP_EOL . ' ', $traits) . PHP_EOL . PHP_EOL; } if (count($this->properties) > 0) { $properties = array_map( - fn (ParameterInterface $property): string => $property->render(4), + static fn (ParameterInterface $property): string => $property->render(4), $this->properties ); @@ -250,7 +250,7 @@ public function render(): string } if (count($this->methods) > 0) { - $methods = array_map(fn (MethodInterface $method): string => $method->render(), $this->methods); + $methods = array_map(static fn (MethodInterface $method): string => $method->render(), $this->methods); $class .= ' ' . implode(PHP_EOL . PHP_EOL . ' ', $methods) . PHP_EOL; } diff --git a/src/Component/Declaration.php b/src/Component/Declaration.php index 5b93e4e..b9e0e46 100644 --- a/src/Component/Declaration.php +++ b/src/Component/Declaration.php @@ -79,7 +79,7 @@ public function renderParameters(): string } return implode(PHP_EOL, array_map( - fn (ParameterInterface $parameter): string => sprintf(' %s,', $parameter->render()), + static fn (ParameterInterface $parameter): string => sprintf(' %s,', $parameter->render()), $this->parameters )); } diff --git a/src/Component/Inject.php b/src/Component/Inject.php index a8f3cd4..27fb508 100644 --- a/src/Component/Inject.php +++ b/src/Component/Inject.php @@ -69,7 +69,8 @@ private function renderWithNamedArguments(): string private function renderWithPositionalArguments(int $spaces = 4): string { $arguments = array_map( - fn (string $argument): string => sprintf('%s%s%s,', PHP_EOL, str_repeat(' ', $spaces + 4), $argument), + static fn (string $argument): string => + sprintf('%s%s%s,', PHP_EOL, str_repeat(' ', $spaces + 4), $argument), $this->positionalArguments ); diff --git a/src/Component/InterfaceFile.php b/src/Component/InterfaceFile.php index 0067187..a5ea24d 100644 --- a/src/Component/InterfaceFile.php +++ b/src/Component/InterfaceFile.php @@ -169,7 +169,7 @@ public function render(): string if (count($this->declarations) > 0) { $declarations = array_map( - fn (Declaration $declaration): string => $declaration->render(), + static fn (Declaration $declaration): string => $declaration->render(), $this->declarations ); diff --git a/src/Component/Method.php b/src/Component/Method.php index 3e76cdd..bf6aa6e 100644 --- a/src/Component/Method.php +++ b/src/Component/Method.php @@ -187,7 +187,7 @@ public function renderInjects(): string return ''; } - $injects = array_map(fn (Inject $inject): string => $inject->render(), $this->injects); + $injects = array_map(static fn (Inject $inject): string => $inject->render(), $this->injects); return implode(PHP_EOL, $injects); } @@ -199,7 +199,7 @@ public function renderParameters(int $spaces = 0): string } return implode(PHP_EOL, array_map( - fn (ParameterInterface $parameter): string => sprintf( + static fn (ParameterInterface $parameter): string => sprintf( '%s%s,', str_repeat(' ', $spaces), $parameter->render() diff --git a/structarmed.php b/structarmed.php new file mode 100644 index 0000000..99a9bed --- /dev/null +++ b/structarmed.php @@ -0,0 +1,51 @@ +withPresets(Preset::PSR4(), Preset::CODEQUALITY()) + + ->layer('ColorEnum', 'src/ColorEnum.php') + ->layer('VisibilityEnum', 'src/VisibilityEnum.php') + ->layer('Context', 'src/Context.php') + ->layer('Config', 'src/Config.php') + ->layer('Message', 'src/Message.php') + ->layer('Maker', 'src/Maker.php') + ->layer('IO', 'src/IO/') + ->layer('Exception', 'src/Exception/') + ->layer('BaseComponent', ['src/Component.php', 'src/Component/'], 'src/Component/Method/') + ->layer('MethodComponent', 'src/Component/Method/') + ->layer('FileSystem', ['src/FileSystem.php', 'src/FileSystem/']) + ->layer('CommonType', 'src/Type/', [ + 'src/Type/Form/', + 'src/Type/Handler/', + 'src/Type/Input/', + 'src/Type/InputFilter/', + ]) + ->layer('FormType', 'src/Type/Form/') + ->layer('HandlerType', 'src/Type/Handler/', 'src/Type/Handler/Api/') + ->layer('ApiHandlerType', 'src/Type/Handler/Api/') + ->layer('InputType', 'src/Type/Input/') + ->layer('InputFilterType', 'src/Type/InputFilter/') + ->ruleset([ + 'ColorEnum' => [], + 'VisibilityEnum' => [], + 'Context' => [], + 'IO' => ['ColorEnum'], + 'Message' => ['ColorEnum', 'Context'], + 'BaseComponent' => ['Context', 'VisibilityEnum', 'MethodComponent'], + 'MethodComponent' => ['+BaseComponent'], + 'Exception' => ['FileSystem'], + 'FileSystem' => ['+BaseComponent', 'Exception'], + 'FormType' => ['CommonType', 'Config', '+FileSystem', '+IO', '+Message'], + 'HandlerType' => ['CommonType', 'Config', '+FileSystem', '+IO', '+Message'], + 'ApiHandlerType' => ['+HandlerType'], + 'InputType' => ['CommonType', 'Config', '+FileSystem', '+IO', '+Message'], + 'InputFilterType' => ['CommonType', 'Config', '+FileSystem', '+IO', '+Message'], + 'CommonType' => ['+FormType', '+ApiHandlerType', '+InputType', '+InputFilterType'], + 'Maker' => ['+CommonType'], + 'Config' => ['Maker'], + ]); diff --git a/test/Component/ClassFileTest.php b/test/Component/ClassFileTest.php index f4bbaee..1693d11 100644 --- a/test/Component/ClassFileTest.php +++ b/test/Component/ClassFileTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\ClassFile; use Dot\Maker\Component\Inject; diff --git a/test/Component/CoreImportTest.php b/test/Component/CoreImportTest.php index 4f4ae70..c0895cd 100644 --- a/test/Component/CoreImportTest.php +++ b/test/Component/CoreImportTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Import; use Dot\Maker\Context; diff --git a/test/Component/DeclarationTest.php b/test/Component/DeclarationTest.php index c6fd406..9f24bbd 100644 --- a/test/Component/DeclarationTest.php +++ b/test/Component/DeclarationTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Declaration; use Dot\Maker\Component\Parameter; diff --git a/test/Component/ImportTest.php b/test/Component/ImportTest.php index 54725ea..7fe8bd0 100644 --- a/test/Component/ImportTest.php +++ b/test/Component/ImportTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Import; use Dot\Maker\Context; diff --git a/test/Component/InjectTest.php b/test/Component/InjectTest.php index b762592..370ce27 100644 --- a/test/Component/InjectTest.php +++ b/test/Component/InjectTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Inject; use PHPUnit\Framework\TestCase; diff --git a/test/Component/InterfaceFileTest.php b/test/Component/InterfaceFileTest.php index ee9c859..9f71eb0 100644 --- a/test/Component/InterfaceFileTest.php +++ b/test/Component/InterfaceFileTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Declaration; use Dot\Maker\Component\InterfaceFile; diff --git a/test/Component/Method/ConstructorTest.php b/test/Component/Method/ConstructorTest.php index 7105a8d..fa27a78 100644 --- a/test/Component/Method/ConstructorTest.php +++ b/test/Component/Method/ConstructorTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component\Method; +namespace DotTest\Maker\Component\Method; use Dot\Maker\Component\Inject; use Dot\Maker\Component\Method\Constructor; diff --git a/test/Component/Method/GetterTest.php b/test/Component/Method/GetterTest.php index 5fb75e1..92c1948 100644 --- a/test/Component/Method/GetterTest.php +++ b/test/Component/Method/GetterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component\Method; +namespace DotTest\Maker\Component\Method; use Dot\Maker\Component\Method\Getter; use Dot\Maker\Component\Parameter; diff --git a/test/Component/Method/SetterTest.php b/test/Component/Method/SetterTest.php index 8f0b172..5407c1b 100644 --- a/test/Component/Method/SetterTest.php +++ b/test/Component/Method/SetterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component\Method; +namespace DotTest\Maker\Component\Method; use Dot\Maker\Component\Method\Setter; use Dot\Maker\Component\Parameter; diff --git a/test/Component/MethodTest.php b/test/Component/MethodTest.php index 86b5c7a..389bb52 100644 --- a/test/Component/MethodTest.php +++ b/test/Component/MethodTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Inject; use Dot\Maker\Component\Method; diff --git a/test/Component/ParameterTest.php b/test/Component/ParameterTest.php index 90c4920..fc4ada5 100644 --- a/test/Component/ParameterTest.php +++ b/test/Component/ParameterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Parameter; use Dot\Maker\VisibilityEnum; diff --git a/test/Component/PromotedPropertyTest.php b/test/Component/PromotedPropertyTest.php index 89c0601..cce09ea 100644 --- a/test/Component/PromotedPropertyTest.php +++ b/test/Component/PromotedPropertyTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\PromotedProperty; use Dot\Maker\VisibilityEnum; diff --git a/test/Component/PropertyTest.php b/test/Component/PropertyTest.php index 71cbbd2..02bef92 100644 --- a/test/Component/PropertyTest.php +++ b/test/Component/PropertyTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Component; +namespace DotTest\Maker\Component; use Dot\Maker\Component\Property; use Dot\Maker\VisibilityEnum;