feat: ajout de phparkitect + début de config pour les domains

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-22 17:16:26 +01:00
parent 4f4f86fb91
commit e444d79101
5 changed files with 247 additions and 2 deletions

View File

@@ -27,6 +27,9 @@ help: ## Outputs this help screen
build: ## Builds the Docker images build: ## Builds the Docker images
@$(DOCKER_COMP) build --pull --no-cache @$(DOCKER_COMP) build --pull --no-cache
phparkitect: ## Vérifie l'architecture avec PHPArkitect
@$(PHP_CONT) vendor/bin/phparkitect check
up: ## Start the docker hub up: ## Start the docker hub
@$(DOCKER_COMP) up -d @$(DOCKER_COMP) up -d

View File

@@ -112,6 +112,7 @@
"doctrine/doctrine-fixtures-bundle": "^3.5", "doctrine/doctrine-fixtures-bundle": "^3.5",
"friendsofphp/php-cs-fixer": "^3.48", "friendsofphp/php-cs-fixer": "^3.48",
"mtdowling/jmespath.php": "^2.7", "mtdowling/jmespath.php": "^2.7",
"phparkitect/phparkitect": "^0.3.33",
"phpmd/phpmd": "^2.15", "phpmd/phpmd": "^2.15",
"phpunit/phpunit": "^10.5", "phpunit/phpunit": "^10.5",
"symfony/browser-kit": "7.0.*", "symfony/browser-kit": "7.0.*",

163
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "e2253575e3f4a0344fe2ff59ac54aad0", "content-hash": "be8113b23da88e97654b9211688e5160",
"packages": [ "packages": [
{ {
"name": "api-platform/core", "name": "api-platform/core",
@@ -10188,6 +10188,84 @@
}, },
"time": "2023-12-10T21:03:43+00:00" "time": "2023-12-10T21:03:43+00:00"
}, },
{
"name": "ondram/ci-detector",
"version": "4.2.0",
"source": {
"type": "git",
"url": "https://github.com/OndraM/ci-detector.git",
"reference": "8b0223b5ed235fd377c75fdd1bfcad05c0f168b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/OndraM/ci-detector/zipball/8b0223b5ed235fd377c75fdd1bfcad05c0f168b8",
"reference": "8b0223b5ed235fd377c75fdd1bfcad05c0f168b8",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.13.2",
"lmc/coding-standard": "^3.0.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9.6.13"
},
"type": "library",
"autoload": {
"psr-4": {
"OndraM\\CiDetector\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ondřej Machulda",
"email": "ondrej.machulda@gmail.com"
}
],
"description": "Detect continuous integration environment and provide unified access to properties of current build",
"keywords": [
"CircleCI",
"Codeship",
"Wercker",
"adapter",
"appveyor",
"aws",
"aws codebuild",
"azure",
"azure devops",
"azure pipelines",
"bamboo",
"bitbucket",
"buddy",
"ci-info",
"codebuild",
"continuous integration",
"continuousphp",
"devops",
"drone",
"github",
"gitlab",
"interface",
"jenkins",
"pipelines",
"sourcehut",
"teamcity",
"travis"
],
"support": {
"issues": "https://github.com/OndraM/ci-detector/issues",
"source": "https://github.com/OndraM/ci-detector/tree/4.2.0"
},
"time": "2024-03-12T13:22:30+00:00"
},
{ {
"name": "pdepend/pdepend", "name": "pdepend/pdepend",
"version": "2.16.2", "version": "2.16.2",
@@ -10362,6 +10440,89 @@
}, },
"time": "2022-02-21T01:04:05+00:00" "time": "2022-02-21T01:04:05+00:00"
}, },
{
"name": "phparkitect/phparkitect",
"version": "0.3.33",
"source": {
"type": "git",
"url": "https://github.com/phparkitect/arkitect.git",
"reference": "aa15c864bef601d797e24f479852ec3f7d35cdd1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phparkitect/arkitect/zipball/aa15c864bef601d797e24f479852ec3f7d35cdd1",
"reference": "aa15c864bef601d797e24f479852ec3f7d35cdd1",
"shasum": ""
},
"require": {
"ext-json": "*",
"nikic/php-parser": "~4",
"ondram/ci-detector": "^4.1",
"php": "^7.1|^8",
"phpstan/phpdoc-parser": "^1.2",
"symfony/console": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/finder": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/polyfill-php80": "^1.20",
"webmozart/assert": "^1.9"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0",
"vimeo/psalm": "^4.6"
},
"bin": [
"bin-stub/phparkitect"
],
"type": "library",
"autoload": {
"psr-4": {
"Arkitect\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Pietro Campagnano",
"email": "hello@pietro.camp"
},
{
"name": "Patrick Luca Fazzi",
"email": "patrick91@live.it"
},
{
"name": "Alessandro Minoccheri",
"email": "alessandro.minoccheri@gmail.com"
},
{
"name": "Michele Orselli",
"email": "michele.orselli@gmail.com"
}
],
"description": "Enforce architectural constraints in your PHP applications",
"support": {
"issues": "https://github.com/phparkitect/arkitect/issues",
"source": "https://github.com/phparkitect/arkitect/tree/0.3.33"
},
"funding": [
{
"url": "https://github.com/AlessandroMinoccheri",
"type": "github"
},
{
"url": "https://github.com/micheleorselli",
"type": "github"
}
],
"time": "2024-05-28T05:56:58+00:00"
},
{ {
"name": "phpmd/phpmd", "name": "phpmd/phpmd",
"version": "2.15.0", "version": "2.15.0",

80
phparkitect.php Normal file
View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
return static function (Config $config): void {
$domainClassSet = ClassSet::fromDir(__DIR__ . '/src/Domain');
$domains = ['Manga', 'Reader', 'Scraping'];
// Classes PHP standards et utilitaires
$standardExceptions = [
'DateTimeImmutable',
'RuntimeException',
'Exception',
'DomainException',
'Symfony\Component\HttpKernel\Exception',
'Throwable',
'InvalidArgumentException',
];
// Dépendances externes autorisées
$externalDependencies = [
'Symfony\Component\Messenger',
'Ramsey\Uuid'
];
// Règle pour le namespace cohérent
$namespaceRule = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new HaveNameMatching('*'))
->because('nous voulons un namespace cohérent pour notre domaine');
$rules = [$namespaceRule];
// Les classes de Application ne doivent pas dépendre de l'infrastructure
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\*\Application'))
->should(new NotDependsOnTheseNamespaces('App\Domain\*\Infrastructure'))
->because('la couche Application ne doit pas dépendre de l\'infrastructure');
// Les classes de Domain ne doivent pas dépendre de l'infrastructure ou de l'application
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\*\Domain'))
->should(new NotDependsOnTheseNamespaces(
'App\Domain\*\Infrastructure',
'App\Domain\*\Application'
))
->because('la couche Domain ne doit pas dépendre de l\'infrastructure ou de l\'application');
// Génération des règles pour chaque domaine
foreach ($domains as $domain) {
// Récupération des autres domaines
$otherDomains = array_filter($domains, fn($d) => $d !== $domain);
$otherDomainsNamespaces = array_map(fn($d) => "App\Domain\\$d\*", $otherDomains);
// Règle pour la couche Domain
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Domain"))
->should(new NotHaveDependencyOutsideNamespace("App\Domain\\$domain\Domain", $standardExceptions))
->because("la couche Domain de $domain ne doit dépendre que de ses propres classes et des exceptions autorisées");
// Règle pour la couche Application
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Application"))
->should(new NotHaveDependencyOutsideNamespace(
"App\Domain\\$domain",
array_merge($standardExceptions, $externalDependencies)
))
->because("la couche Application de $domain ne peut dépendre que de son propre domaine et des dépendances autorisées");
}
$config->add($domainClassSet, ...$rules);
};

View File

@@ -2,7 +2,7 @@
namespace App\Domain\Scraping\Domain\Model\ValueObject; namespace App\Domain\Scraping\Domain\Model\ValueObject;
use Symfony\Component\HttpClient\Exception\InvalidArgumentException; use InvalidArgumentException;
class ChapterUrl class ChapterUrl
{ {