Skip to content

Commit

Permalink
Add some PHP arkitect rules
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Nov 30, 2023
1 parent 968c389 commit f8f01d7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ jobs:
name: Run Psalm
run: vendor/bin/psalm --php-version=${{ matrix.php }}

-
name: Run PHPArkitect
run: (cd src/Component && vendor/bin/phparkitect check)

-
name: Run analysis
run: |
Expand Down
6 changes: 6 additions & 0 deletions src/Bundle/spec/Event/ResourceControllerEventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Resource\Symfony\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\Response;

final class ResourceControllerEventSpec extends ObjectBehavior
Expand Down Expand Up @@ -94,4 +95,9 @@ function it_has_not_response_if_it_was_not_set_before(): void
{
$this->hasResponse()->shouldReturn(false);
}

function it_should_be_an_alias_of_generic_event(): void
{
$this->shouldBeAnInstanceOf(GenericEvent::class);
}
}
3 changes: 2 additions & 1 deletion src/Component/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"sylius/grid": "^1.7 || ^1.12",
"symfony/serializer": "^5.4 || ^6.0",
"symfony/workflow": "^5.4 || ^6.0",
"twig/twig": "^2.12 || ^3.0"
"twig/twig": "^2.12 || ^3.0",
"phparkitect/phparkitect": "^0.3"
},
"extra": {
"branch-alias": {
Expand Down
38 changes: 38 additions & 0 deletions src/Component/phparkitect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\IsFinal;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;

return static function (Config $config): void
{
$srcClassSet = ClassSet::fromDir(__DIR__ . '/src');

$rules = [];

$rules[] = Rule::allClasses()
->except(
// Except class aliases
'Sylius\Resource\Symfony\EventDispatcher\*',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Resource'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle'))
->because('Sylius Resource should be stand-alone')
;

$rules[] = Rule::allClasses()
->except(
'Sylius\Resource\Metadata\HttpOperation',
'Sylius\Resource\Symfony\EventDispatcher\GenericEvent',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Resource'))
->should(new IsFinal())
->because('We want to avoid forgetting final classes');

$config->add($srcClassSet, ...$rules);
};

0 comments on commit f8f01d7

Please sign in to comment.