| Conditions | 28 |
| Paths | 81 |
| Total Lines | 104 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 65 | public function refactor(Node $node): FileNode|Node|Namespace_|null |
||
| 66 | { |
||
| 67 | if ($node instanceof FileNode && $node->isNamespaced()) { |
||
| 68 | // handle in Namespace_ node |
||
| 69 | return null; |
||
| 70 | } |
||
| 71 | $hasChanged = false; |
||
| 72 | |||
| 73 | foreach ($node->stmts as $stmt) { |
||
| 74 | if (! $stmt instanceof Use_) { |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | |||
| 78 | if (count($stmt->uses) !== 1) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (! isset($stmt->uses[0])) { |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | $aliasName = $stmt->uses[0]->alias instanceof Identifier ? $stmt->uses[0]->alias->toString() : null; |
||
| 86 | |||
| 87 | if ($aliasName === null) { |
||
| 88 | continue; |
||
| 89 | } |
||
| 90 | |||
| 91 | $useNameToCheck = $stmt->uses[0]->name->toString(); |
||
| 92 | $aliasUseLastName = Strings::after($useNameToCheck, '\\', -1) ?? $useNameToCheck; |
||
| 93 | |||
| 94 | foreach ($node->stmts as $compareStmt) { |
||
| 95 | if ( |
||
| 96 | ( |
||
| 97 | $compareStmt instanceof Node\Stmt\Class_ |
||
| 98 | || $compareStmt instanceof Node\Stmt\Interface_ |
||
| 99 | || $compareStmt instanceof Node\Stmt\Trait_ |
||
| 100 | || $compareStmt instanceof Node\Stmt\Enum_ |
||
| 101 | ) |
||
| 102 | && $compareStmt->name?->name !== null |
||
| 103 | // Ensure the alias's class name does not match the class/interface/trait/enum class name |
||
| 104 | && strtolower($compareStmt->name->name ?? '') === strtolower($aliasUseLastName) |
||
| 105 | ) { |
||
| 106 | // If it did this alias is required and we should move onto the next alias |
||
| 107 | continue 2; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($compareStmt === $stmt) { |
||
| 111 | continue; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (! $compareStmt instanceof Use_) { |
||
| 115 | continue; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (count($compareStmt->uses) !== 1) { |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | |||
| 122 | if (! isset($compareStmt->uses[0])) { |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | $use = $compareStmt->uses[0]->name->toString(); |
||
| 127 | $lastName = Strings::after($use, '\\', -1) ?? $use; |
||
| 128 | $useAliasName = $stmt->uses[0]->alias instanceof Identifier ? $stmt->uses[0]->alias->toString() : null; |
||
| 129 | $useHasAlias = $useAliasName !== null; |
||
| 130 | |||
| 131 | if ( |
||
| 132 | // Ensure the alias is not the same as the class name of another use statement |
||
| 133 | strtolower($lastName) === strtolower($aliasName) |
||
| 134 | // Ensure the alias's class name is not the same as the class name of another use statement that has no alias |
||
| 135 | || (! $useHasAlias && strtolower($lastName) === strtolower($aliasUseLastName)) |
||
| 136 | // Ensure the alias is not the same as the alias of another use statement that has an alias |
||
| 137 | || ($useHasAlias && strtolower($useAliasName) === strtolower($aliasName)) |
||
| 138 | ) { |
||
| 139 | // If it matched then this alias is required and we should move onto the next alias |
||
| 140 | continue 2; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | $stmt->uses[0]->alias = null; |
||
| 145 | $hasChanged = true; |
||
| 146 | |||
| 147 | $nodeFinder = new NodeFinder(); |
||
| 148 | // Get all nodes |
||
| 149 | $allNodes = $nodeFinder->findInstanceOf($node, Node::class); |
||
| 150 | |||
| 151 | foreach ($allNodes as $allNode) { |
||
| 152 | $this->modifyComments($allNode, $aliasName, $aliasUseLastName); |
||
| 153 | $this->modifyNodeClassName($allNode, 'name', $aliasName, $aliasUseLastName); |
||
| 154 | $this->modifyNodeClassName($allNode, 'class', $aliasName, $aliasUseLastName); |
||
| 155 | $this->modifyNodeClassName($allNode, 'extends', $aliasName, $aliasUseLastName); |
||
| 156 | $this->modifyNodeClassName($allNode, 'type', $aliasName, $aliasUseLastName); |
||
| 157 | $this->modifyNodeClassName($allNode, 'returnType', $aliasName, $aliasUseLastName); |
||
| 158 | $this->modifyNodes($allNode, 'implements', $aliasName, $aliasUseLastName); |
||
| 159 | $this->modifyNodes($allNode, 'extends', $aliasName, $aliasUseLastName); |
||
| 160 | $this->modifyNodes($allNode, 'traits', $aliasName, $aliasUseLastName); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | if ($hasChanged) { |
||
| 165 | return $node; |
||
| 166 | } |
||
| 167 | |||
| 168 | return null; |
||
| 169 | } |
||
| 233 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths