| Conditions | 23 |
| Paths | 35 |
| Total Lines | 101 |
| Code Lines | 57 |
| Lines | 30 |
| Ratio | 29.7 % |
| Changes | 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 |
||
| 125 | public function enterNode(Node $node) |
||
| 126 | { |
||
| 127 | /** |
||
| 128 | * determine domain from namespace of files. |
||
| 129 | * Finder appears to start with root level files so Namespace is correct for remaining files |
||
| 130 | */ |
||
| 131 | if ($node instanceof Namespace_) { |
||
|
1 ignored issue
–
show
|
|||
| 132 | if (isset($node->name)) { |
||
| 133 | $bundle = $this->getBundleFromNodeNamespace($node->name->toString()); |
||
| 134 | if (isset($bundle) && $bundle instanceof AbstractBundle) { |
||
| 135 | $this->domain = $bundle->getTranslationDomain(); |
||
| 136 | } else { |
||
| 137 | $this->domain = 'zikula'; |
||
| 138 | } |
||
| 139 | |||
| 140 | return; |
||
| 141 | } else { |
||
| 142 | foreach ($node->stmts as $node) { |
||
| 143 | $this->enterNode($node); |
||
| 144 | } |
||
| 145 | |||
| 146 | return; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | if (!$node instanceof MethodCall |
||
|
1 ignored issue
–
show
|
|||
| 150 | || !is_string($node->name) |
||
| 151 | || !in_array(strtolower($node->name), $this->methodNames) |
||
| 152 | ) { |
||
| 153 | $this->previousNode = $node; |
||
| 154 | |||
| 155 | return; |
||
| 156 | } |
||
| 157 | |||
| 158 | $ignore = false; |
||
| 159 | $desc = $meaning = null; |
||
| 160 | if (null !== $docComment = $this->getDocCommentForNode($node)) { |
||
| 161 | foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) { |
||
| 162 | if ($annot instanceof Ignore) { |
||
|
1 ignored issue
–
show
|
|||
| 163 | $ignore = true; |
||
| 164 | } elseif ($annot instanceof Desc) { |
||
|
1 ignored issue
–
show
|
|||
| 165 | $desc = $annot->text; |
||
| 166 | } elseif ($annot instanceof Meaning) { |
||
|
1 ignored issue
–
show
|
|||
| 167 | $meaning = $annot->text; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | View Code Duplication | if (!$node->args[0]->value instanceof String_) { |
|
|
1 ignored issue
–
show
|
|||
| 173 | if ($ignore) { |
||
| 174 | return; |
||
| 175 | } |
||
| 176 | |||
| 177 | $message = sprintf('Can only extract the translation id from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine()); |
||
| 178 | |||
| 179 | if ($this->logger) { |
||
| 180 | $this->logger->error($message); |
||
| 181 | |||
| 182 | return; |
||
| 183 | } |
||
| 184 | |||
| 185 | throw new RuntimeException($message); |
||
| 186 | } |
||
| 187 | |||
| 188 | $id = $node->args[0]->value->value; |
||
| 189 | if (in_array(strtolower($node->name), ['_n', '_fn'], true)) { |
||
| 190 | // concatenate pluralized strings from zikula functions |
||
| 191 | $id = $node->args[0]->value->value . '|' . $node->args[1]->value->value; |
||
| 192 | } |
||
| 193 | |||
| 194 | // determine location of domain |
||
| 195 | $domainIndex = array_search(strtolower($node->name), $this->methodNames); |
||
| 196 | |||
| 197 | if (isset($node->args[$domainIndex])) { |
||
| 198 | View Code Duplication | if (!$node->args[$domainIndex]->value instanceof String_) { |
|
|
1 ignored issue
–
show
|
|||
| 199 | if ($ignore) { |
||
| 200 | return; |
||
| 201 | } |
||
| 202 | |||
| 203 | $message = sprintf('Can only extract the translation domain from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine()); |
||
| 204 | |||
| 205 | if ($this->logger) { |
||
| 206 | $this->logger->error($message); |
||
| 207 | |||
| 208 | return; |
||
| 209 | } |
||
| 210 | |||
| 211 | throw new RuntimeException($message); |
||
| 212 | } |
||
| 213 | |||
| 214 | $domain = $node->args[$domainIndex]->value->value; |
||
| 215 | } else { |
||
| 216 | $domain = !empty($this->domain) ? $this->domain : 'zikula'; |
||
| 217 | } |
||
| 218 | |||
| 219 | $message = new Message($id, $domain); |
||
| 220 | $message->setDesc($desc); |
||
| 221 | $message->setMeaning($meaning); |
||
| 222 | $message->addSource(new FileSource((string)$this->file, $node->getLine())); |
||
| 223 | |||
| 224 | $this->catalogue->add($message); |
||
| 225 | } |
||
| 226 | |||
| 295 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.