| Conditions | 15 |
| Paths | 18 |
| Total Lines | 71 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 32 | public static function parseAttributes(Cursor $cursor): array |
||
| 33 | { |
||
| 34 | $state = $cursor->saveState(); |
||
| 35 | $cursor->advanceToNextNonSpaceOrNewline(); |
||
| 36 | |||
| 37 | // Quick check to see if we might have attributes |
||
| 38 | if ($cursor->getCharacter() !== '{') { |
||
| 39 | $cursor->restoreState($state); |
||
| 40 | |||
| 41 | return []; |
||
| 42 | } |
||
| 43 | |||
| 44 | // Attempt to match the entire attribute list expression |
||
| 45 | // While this is less performant than checking for '{' now and '}' later, it simplifies |
||
| 46 | // matching individual attributes since they won't need to look ahead for the closing '}' |
||
| 47 | // while dealing with the fact that attributes can technically contain curly braces. |
||
| 48 | // So we'll just match the start and end braces up front. |
||
| 49 | $attributeExpression = $cursor->match(self::ATTRIBUTE_LIST); |
||
| 50 | if ($attributeExpression === null) { |
||
| 51 | $cursor->restoreState($state); |
||
| 52 | |||
| 53 | return []; |
||
| 54 | } |
||
| 55 | |||
| 56 | // Trim the leading '{' or '{:' and the trailing '}' |
||
| 57 | $attributeExpression = \ltrim(\substr($attributeExpression, 1, -1), ':'); |
||
| 58 | $attributeCursor = new Cursor($attributeExpression); |
||
| 59 | |||
| 60 | /** @var array<string, mixed> $attributes */ |
||
| 61 | $attributes = []; |
||
| 62 | while ($attribute = \trim((string) $attributeCursor->match('/^' . self::SINGLE_ATTRIBUTE . '/i'))) { |
||
| 63 | if ($attribute[0] === '#') { |
||
| 64 | $attributes['id'] = \substr($attribute, 1); |
||
| 65 | |||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($attribute[0] === '.') { |
||
| 70 | $attributes['class'][] = \substr($attribute, 1); |
||
| 71 | |||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** @psalm-suppress PossiblyUndefinedArrayOffset */ |
||
| 76 | [$name, $value] = \explode('=', $attribute, 2); |
||
| 77 | |||
| 78 | if ($value === 'true') { |
||
| 79 | $attributes[$name] = true; |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | |||
| 83 | $first = $value[0]; |
||
| 84 | $last = \substr($value, -1); |
||
| 85 | if (($first === '"' && $last === '"') || ($first === "'" && $last === "'") && \strlen($value) > 1) { |
||
| 86 | $value = \substr($value, 1, -1); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (\strtolower(\trim($name)) === 'class') { |
||
| 90 | foreach (\array_filter(\explode(' ', \trim($value))) as $class) { |
||
| 91 | $attributes['class'][] = $class; |
||
| 92 | } |
||
| 93 | } else { |
||
| 94 | $attributes[\trim($name)] = \trim($value); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | if (isset($attributes['class'])) { |
||
| 99 | $attributes['class'] = \implode(' ', (array) $attributes['class']); |
||
| 100 | } |
||
| 101 | |||
| 102 | return $attributes; |
||
| 103 | } |
||
| 181 |
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