forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phparkitect.php
109 lines (101 loc) · 4.04 KB
/
phparkitect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\Extend;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\IsNotAbstract;
use Arkitect\Expression\ForClasses\IsFinal;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
use PhpSpec\ObjectBehavior;
return static function (Config $config): void
{
$specClassSet = ClassSet::fromDir(__DIR__ . '/src/Sylius/{Behat,Component/*,Bundle/*}/spec');
$config->add(
$specClassSet,
Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->should(new HaveNameMatching('*Spec'))
->because('Specifications should follow PHPSpec naming convention')
,
Rule::allClasses()
->that(new Extend(ObjectBehavior::class))
->andThat(new IsNotAbstract())
->should(new IsFinal())
->because('Specifications should not be extendable')
,
);
$testsClassSet = ClassSet::fromDir(__DIR__ . '{/tests,/src/Sylius/Bundle/*/Tests}');
$config->add(
$testsClassSet,
Rule::allClasses()
->that(new HaveNameMatching('*Test$'))
->should(new IsFinal())
->because('Tests should not be extendable')
,
);
$separationClassSet = ClassSet::fromDir(__DIR__ . '/src/Sylius/{Component,Bundle}');
$config->add(
$separationClassSet,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Component'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle'))
->because('Components should not depend on bundles')
,
Rule::allClasses()
->except('Sylius\Component\Core')
->that(new ResideInOneOfTheseNamespaces('Sylius\Component'))
->should(new NotDependsOnTheseNamespaces('Sylius\Component\Core'))
->because('Stand-alone components should not depend on Core')
,
Rule::allClasses()
->except(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\CoreBundle',
'Sylius\Bundle\PayumBundle',
'Sylius\Bundle\ShopBundle',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle'))
->should(new NotDependsOnTheseNamespaces('Sylius\Component\Core'))
->because('Stand-alone bundles should not depend on Core')
,
Rule::allClasses()
->except(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\CoreBundle',
'Sylius\Bundle\ShopBundle',
)
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle'))
->should(new NotDependsOnTheseNamespaces('Sylius\Bundle\CoreBundle'))
->because('Stand-alone bundles should not depend on CoreBundle')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\ShopBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ApiBundle',
))
->because('Shop should not depend on Admin and Api')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\AdminBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\ApiBundle',
'Sylius\Bundle\ShopBundle',
))
->because('Admin should not depend on Shop and Api')
,
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Sylius\Bundle\ApiBundle'))
->should(new NotDependsOnTheseNamespaces(
'Sylius\Bundle\AdminBundle',
'Sylius\Bundle\ShopBundle',
))
->because('Api should not depend on Admin and Shop')
,
);
};