Conditions | 10 |
Paths | 4 |
Total Lines | 48 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
58 | public function find(): iterable |
||
59 | { |
||
60 | $countInterfaces = count($this->interfaces); |
||
61 | $countAttributes = count($this->attributes); |
||
62 | |||
63 | if ($countInterfaces === 0 && $countAttributes === 0) { |
||
64 | return []; |
||
65 | } |
||
66 | |||
67 | $files = (new Finder()) |
||
68 | ->in($this->directory) |
||
69 | ->name('*.php') |
||
70 | ->sortByName() |
||
71 | ->files(); |
||
72 | |||
73 | $interfaces = $this->interfaces; |
||
74 | $attributes = $this->attributes; |
||
75 | |||
76 | foreach ($files as $file) { |
||
77 | $nodes = $this->parser->parse(file_get_contents($file->getRealPath())); |
||
78 | $this->traverser->traverse($nodes); |
||
|
|||
79 | /** |
||
80 | * @var $result Node\Stmt\Class_[] |
||
81 | */ |
||
82 | $result = $this->nodeFinder->find( |
||
83 | $nodes, |
||
84 | function (Node $node) use ($interfaces, $countInterfaces, $attributes, $countAttributes) { |
||
85 | if (!$node instanceof Node\Stmt\Class_) { |
||
86 | return false; |
||
87 | } |
||
88 | $interfacesNames = array_map(fn (Node\Name $name) => $name->toString(), $node->implements); |
||
89 | if (count(array_intersect($interfaces, $interfacesNames)) !== $countInterfaces) { |
||
90 | return false; |
||
91 | } |
||
92 | $attributesNames = []; |
||
93 | foreach ($node->attrGroups as $attrGroup) { |
||
94 | foreach ($attrGroup->attrs as $attr) { |
||
95 | $attributesNames[] = $attr->name->toString(); |
||
96 | } |
||
97 | } |
||
98 | if (count(array_intersect($attributes, $attributesNames)) !== $countAttributes) { |
||
99 | return false; |
||
100 | } |
||
101 | return true; |
||
102 | } |
||
103 | ); |
||
104 | foreach ($result as $class) { |
||
105 | yield $class->namespacedName->toString(); |
||
106 | } |
||
111 |