| Conditions | 24 |
| Paths | 69 |
| Total Lines | 95 |
| Code Lines | 53 |
| 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 |
||
| 66 | public function refactor(Node $node): FileNode|Node|Namespace_|null |
||
| 67 | { |
||
| 68 | if ($node instanceof FileNode && $node->isNamespaced()) { |
||
| 69 | // handle in Namespace_ node |
||
| 70 | return null; |
||
| 71 | } |
||
| 72 | $hasChanged = false; |
||
| 73 | |||
| 74 | foreach ($node->stmts as $stmt) { |
||
| 75 | if (! $stmt instanceof Use_) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | |||
| 79 | if (count($stmt->uses) !== 1) { |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | |||
| 83 | if (! isset($stmt->uses[0])) { |
||
| 84 | continue; |
||
| 85 | } |
||
| 86 | $aliasName = $stmt->uses[0]->alias instanceof Identifier ? $stmt->uses[0]->alias->toString() : null; |
||
| 87 | |||
| 88 | if ($aliasName === null) { |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | $useName = $stmt->uses[0]->name->toString(); |
||
| 93 | $aliasUseLastName = Strings::after($useName, '\\', -1) ?? $useName; |
||
| 94 | |||
| 95 | foreach ($node->stmts as $compareStmt) { |
||
| 96 | if ( |
||
| 97 | ( |
||
| 98 | $compareStmt instanceof Node\Stmt\Class_ |
||
| 99 | || $compareStmt instanceof Node\Stmt\Interface_ |
||
| 100 | || $compareStmt instanceof Node\Stmt\Trait_ |
||
| 101 | || $compareStmt instanceof Node\Stmt\Enum_ |
||
| 102 | ) |
||
| 103 | && $compareStmt?->name?->name !== null |
||
| 104 | && strtolower($compareStmt->name->name ?? '') === strtolower($aliasUseLastName) |
||
| 105 | ) { |
||
| 106 | continue 2; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($compareStmt === $stmt) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | if (! $compareStmt instanceof Use_) { |
||
| 114 | continue; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (count($compareStmt->uses) !== 1) { |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (! isset($compareStmt->uses[0])) { |
||
| 122 | continue; |
||
| 123 | } |
||
| 124 | |||
| 125 | $use = $compareStmt->uses[0]->name->toString(); |
||
| 126 | $lastName = Strings::after($use, '\\', -1) ?? $use; |
||
| 127 | |||
| 128 | if (strtolower($lastName) === strtolower($aliasName) || strtolower($lastName) === strtolower($aliasUseLastName)) { |
||
| 129 | continue 2; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $stmt->uses[0]->alias = null; |
||
| 134 | $hasChanged = true; |
||
| 135 | |||
| 136 | $nodeFinder = new NodeFinder(); |
||
| 137 | $allNodes = $nodeFinder->findInstanceOf($node, Node::class); |
||
| 138 | |||
| 139 | foreach ($allNodes as $allNode) { |
||
| 140 | $this->modifyComments($allNode, $aliasName, $aliasUseLastName); |
||
| 141 | $this->modifyNodeClassName($allNode, 'name', $aliasName, $aliasUseLastName); |
||
| 142 | $this->modifyNodeClassName($allNode, 'class', $aliasName, $aliasUseLastName); |
||
| 143 | $this->modifyNodeClassName($allNode, 'extends', $aliasName, $aliasUseLastName); |
||
| 144 | $this->modifyNodeClassName($allNode, 'type', $aliasName, $aliasUseLastName); |
||
| 145 | $this->modifyNodeClassName($allNode, 'returnType', $aliasName, $aliasUseLastName); |
||
| 146 | $this->modifyNodes($allNode, 'implements', $aliasName, $aliasUseLastName); |
||
| 147 | $this->modifyNodes($allNode, 'extends', $aliasName, $aliasUseLastName); |
||
| 148 | $this->modifyNodes($allNode, 'traits', $aliasName, $aliasUseLastName); |
||
| 149 | } |
||
| 150 | |||
| 151 | // if ($aliasName === 'EnumTrait') { |
||
| 152 | // file_put_contents(__DIR__ . 'traituseexample.json', json_encode($node)); |
||
| 153 | // } |
||
| 154 | } |
||
| 155 | |||
| 156 | if ($hasChanged) { |
||
| 157 | return $node; |
||
| 158 | } |
||
| 159 | |||
| 160 | return null; |
||
| 161 | } |
||
| 225 |
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