anonymous()
last analyzed

Size

Total Lines 149
Code Lines 109

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 109
dl 0
loc 149
c 0
b 0
f 0
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Arkitect\ClassSet;
0 ignored issues
show
Bug introduced by
The type Arkitect\ClassSet was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Arkitect\CLI\Config;
0 ignored issues
show
Bug introduced by
The type Arkitect\CLI\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Arkitect\Expression\ForClasses\Extend;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\Extend was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Arkitect\Expression\ForClasses\HaveAttribute;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\HaveAttribute was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Arkitect\Expression\ForClasses\HaveNameMatching;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\HaveNameMatching was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Arkitect\Expression\ForClasses\IsEnum;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Arkitect\Expression\ForClasses\IsFinal;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsFinal was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Arkitect\Expression\ForClasses\IsInterface;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Arkitect\Expression\ForClasses\IsNotAbstract;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsNotAbstract was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Arkitect\Expression\ForClasses\IsNotEnum;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsNotEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Arkitect\Expression\ForClasses\IsNotInterface;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsNotInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Arkitect\Expression\ForClasses\IsNotTrait;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsNotTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Arkitect\Expression\ForClasses\IsTrait;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\IsTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Arkitect\Expression\ForClasses\NotHaveNameMatching;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForClasses\NotHaveNameMatching was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Arkitect\Expression\ForClasses\NotResideInTheseNamespaces;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForC...ResideInTheseNamespaces was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
0 ignored issues
show
Bug introduced by
The type Arkitect\Expression\ForC...eInOneOfTheseNamespaces was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Arkitect\Rules\Rule;
0 ignored issues
show
Bug introduced by
The type Arkitect\Rules\Rule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Valkyrja\Container\Support\Provider;
32
use Valkyrja\Orm\Entity\Entity;
33
use Valkyrja\Type\Model\Model;
34
use Valkyrja\Type\Type;
35
36
return static function (Config $config): void {
37
    $srcClassSet  = ClassSet::fromDir(__DIR__ . '/../../../src');
38
    $testClassSet = ClassSet::fromDir(__DIR__ . '/../../../tests');
39
40
    $srcRules  = [];
41
    $testRules = [];
42
43
    // $srcRules[] = Rule::allClasses()
44
    //                   ->that(new ResideInOneOfTheseNamespaces('*'))
45
    //                   ->should(new ContainDocBlockLike('*@author Melech Mizrachi'))
46
    //                   ->because('All classes should have an author');
47
48
    $srcRules[] = Rule::allClasses()
49
                      ->that(new HaveAttribute(Attribute::class))
50
                      ->should(new ResideInOneOfTheseNamespaces('*Attribute\\'))
51
                      ->because('All attributes should exist in an appropriate namespace');
52
53
    // $srcRules[] = Rule::allClasses()
54
    //                   ->that(new IsAbstract())
55
    //                   ->andThat(new IsNotInterface())
56
    //                   ->andThat(new IsNotFinal())
57
    //                   ->andThat(new IsNotEnum())
58
    //                   ->andThat(new IsNotTrait())
59
    //                   ->andThat(new NotHaveNameMatching('*Factory'))
60
    //                   ->andThat(new NotHaveNameMatching('*Provider'))
61
    //                   ->andThat(new NotHaveNameMatching('*Security'))
62
    //                   ->andThat(new NotResideInTheseNamespaces('*Provider'))
63
    //                   ->should(new HaveNameMatching('*Abstract'))
64
    //                   ->because('All abstract classes should be properly named');
65
66
    $srcRules[] = Rule::allClasses()
67
                      ->that(new IsFinal())
68
                      ->andThat(new IsNotEnum())
69
                      ->andThat(new IsNotInterface())
70
                      ->andThat(new IsNotAbstract())
71
                      ->andThat(new IsNotTrait())
72
                      ->andThat(new NotHaveNameMatching('*Security'))
73
                      ->andThat(new NotHaveNameMatching('*Provider'))
74
                      ->should(new ResideInOneOfTheseNamespaces('*Constant\\'))
75
                      ->because('All final classes are constants and should exist in an appropriate namespace');
76
77
    $srcRules[] = Rule::allClasses()
78
                      ->that(new ResideInOneOfTheseNamespaces('*Constant\\'))
79
                      ->should(new IsFinal())
80
                      ->because('All constants should be final');
81
82
    $srcRules[] = Rule::allClasses()
83
                      ->that(new Extend(Provider::class))
84
                      ->should(new HaveNameMatching('*ServiceProvider'))
85
                      ->because('All service providers should be named appropriately');
86
87
    $srcRules[] = Rule::allClasses()
88
                      ->that(new Extend(Provider::class))
89
                      ->should(new ResideInOneOfTheseNamespaces('*Provider\\'))
90
                      ->because('All service providers should exist in an appropriate namespace');
91
92
    $srcRules[] = Rule::allClasses()
93
                      ->that(new HaveNameMatching('*Factory'))
94
                      ->should(new ResideInOneOfTheseNamespaces('*Factory\\'))
95
                      ->because('All factories should exist in an appropriate namespace');
96
97
    $srcRules[] = Rule::allClasses()
98
                      ->that(new HaveNameMatching('*Command'))
99
                      ->andThat(new NotResideInTheseNamespaces('*Cli\\Routing\\Attribute\\'))
100
                      ->andThat(new NotResideInTheseNamespaces('*Cli\\Routing\\Data\\'))
101
                      ->andThat(new NotHaveNameMatching('*Handler'))
102
                      ->andThat(new NotHaveNameMatching('*Middleware'))
103
                      ->should(new ResideInOneOfTheseNamespaces('*Cli\\Command\\'))
104
                      ->because('All cli commands should exist in an appropriate namespace');
105
106
    $srcRules[] = Rule::allClasses()
107
                      ->that(new HaveNameMatching('*Security'))
108
                      ->should(new ResideInOneOfTheseNamespaces('*Security\\'))
109
                      ->because('All security classes should exist in an appropriate namespace');
110
111
    $srcRules[] = Rule::allClasses()
112
                      ->that(new HaveNameMatching('*Security'))
113
                      ->should(new IsFinal())
114
                      ->because('All security classes should be final');
115
116
    $srcRules[] = Rule::allClasses()
117
                      ->that(new Extend(Throwable::class))
118
                      ->should(new ResideInOneOfTheseNamespaces('*Exception\\'))
119
                      ->because('All throwable objects or interfaces should exist in an appropriate namespace');
120
121
    $srcRules[] = Rule::allClasses()
122
                      ->that(new Extend(Type::class))
123
                      ->andThat(new NotResideInTheseNamespaces('*Config'))
124
                      ->andThat(new NotResideInTheseNamespaces('*Entity'))
125
                      ->andThat(new NotResideInTheseNamespaces('*Model'))
126
                      ->should(new ResideInOneOfTheseNamespaces('*Type\\'))
127
                      ->because('All types should exist in an appropriate namespace');
128
129
    $srcRules[] = Rule::allClasses()
130
                      ->that(new Extend(Model::class))
131
                      ->andThat(new NotResideInTheseNamespaces('*Config'))
132
                      ->andThat(new NotResideInTheseNamespaces('*Entity'))
133
                      ->should(new ResideInOneOfTheseNamespaces('*Model\\'))
134
                      ->because('All models should exist in an appropriate namespace');
135
136
    $srcRules[] = Rule::allClasses()
137
                      ->that(new Extend(Entity::class))
138
                      ->should(new ResideInOneOfTheseNamespaces('*Entity\\'))
139
                      ->because('All entities should exist in an appropriate namespace');
140
141
    $srcRules[] = Rule::allClasses()
142
                      ->that(new IsInterface())
143
                      ->andThat(new NotResideInTheseNamespaces('*Exception\\'))
144
                      ->should(new ResideInOneOfTheseNamespaces('*Contract\\'))
145
                      ->because('All interfaces are contracts and should be in an appropriate namespace');
146
147
    $srcRules[] = Rule::allClasses()
148
                      ->that(new IsEnum())
149
                      ->should(new ResideInOneOfTheseNamespaces('*Enum\\'))
150
                      ->because('All enums should be in an appropriate namespace');
151
152
    $testRules[] = Rule::allClasses()
153
                       ->that(new ResideInOneOfTheseNamespaces('*Classes\\'))
154
                       ->andThat(new NotHaveNameMatching('*Enum'))
155
                       ->andThat(new IsNotTrait())
156
                       ->should(new HaveNameMatching('*Class'))
157
                       ->because('Testable classes should be named appropriately');
158
159
    $testRules[] = Rule::allClasses()
160
                       ->that(new ResideInOneOfTheseNamespaces('*Classes\\'))
161
                       ->should(new NotHaveNameMatching('*Test'))
162
                       ->because('Testable classes are not tests');
163
164
    $testRules[] = Rule::allClasses()
165
                       ->that(new NotHaveNameMatching('*Test'))
166
                       ->should(new NotResideInTheseNamespaces('*Unit\\', '*Functional\\'))
167
                       ->because('Only tests should be in namespace');
168
169
    $testRules[] = Rule::allClasses()
170
                       ->that(new IsTrait())
171
                       ->andThat(new NotHaveNameMatching('TestCase'))
172
                       ->should(new ResideInOneOfTheseNamespaces('*Trait\\'))
173
                       ->because('All test traits should be in an appropriate namespace');
174
175
    $testRules[] = Rule::allClasses()
176
                       ->that(new IsTrait())
177
                       ->andThat(new NotHaveNameMatching('TestCase'))
178
                       ->should(new HaveNameMatching('*Trait'))
179
                       ->because('All test traits should be named appropriately');
180
181
    $config
182
        ->add($srcClassSet, ...$srcRules);
183
    $config
184
        ->add($testClassSet, ...$testRules);
185
};
186