| Conditions | 14 |
| Paths | 34 |
| Total Lines | 74 |
| Code Lines | 41 |
| 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 declare(strict_types=1); |
||
| 47 | public function processNode(Node $node, Scope $scope): array |
||
| 48 | { |
||
| 49 | if (!$scope->isInClass()) { |
||
| 50 | return []; |
||
| 51 | } |
||
| 52 | |||
| 53 | $definitionClassReflection = $scope->getClassReflection()->getNativeReflection(); |
||
| 54 | $className = $definitionClassReflection->getName(); |
||
| 55 | if (str_contains($className, 'Test')) { |
||
| 56 | //if in a test namespace, don't care |
||
| 57 | return []; |
||
| 58 | } |
||
| 59 | |||
| 60 | if (!$node->class instanceof Node\Name) { |
||
| 61 | return []; |
||
| 62 | } |
||
| 63 | |||
| 64 | if (!\in_array($node->class->toString(), self::ASSOCIATIONS_WITH_AUTOLOAD, true)) { |
||
| 65 | return []; |
||
| 66 | } |
||
| 67 | |||
| 68 | $classReflection = $this->reflectionProvider |
||
| 69 | ->getClass($node->class->toString()) |
||
| 70 | ->getNativeReflection(); |
||
| 71 | |||
| 72 | $construct = $classReflection->getMethod('__construct'); |
||
| 73 | |||
| 74 | $autoloadParamPosition = null; |
||
| 75 | $propertyNameParamPosition = null; |
||
| 76 | foreach ($construct->getParameters() as $param) { |
||
| 77 | if ($param->name === 'autoload') { |
||
| 78 | $autoloadParamPosition = $param->getPosition(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($param->name === 'propertyName') { |
||
| 82 | $propertyNameParamPosition = $param->getPosition(); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($autoloadParamPosition === null || $propertyNameParamPosition === null) { |
||
| 87 | //cannot find autoload or propertyName parameter |
||
| 88 | return []; |
||
| 89 | } |
||
| 90 | |||
| 91 | if (!isset($node->getArgs()[$autoloadParamPosition])) { |
||
| 92 | //autoload parameter not passed |
||
| 93 | return []; |
||
| 94 | } |
||
| 95 | |||
| 96 | $autoloadValueExpr = $node->getArgs()[$autoloadParamPosition]->value; |
||
| 97 | $propertyNameValueExpr = $node->getArgs()[$propertyNameParamPosition]->value; |
||
| 98 | |||
| 99 | if ($scope->getType($autoloadValueExpr)->isTrue()->yes()) { |
||
| 100 | $constant = $definitionClassReflection->getConstant('ENTITY_NAME'); |
||
| 101 | |||
| 102 | if ($constant === false) { |
||
| 103 | return []; |
||
| 104 | } |
||
| 105 | |||
| 106 | $propType = $scope->getType($propertyNameValueExpr); |
||
| 107 | if (!$propType instanceof ConstantStringType) { |
||
| 108 | return []; |
||
| 109 | } |
||
| 110 | |||
| 111 | return [ |
||
| 112 | RuleErrorBuilder::message(sprintf( |
||
| 113 | '%s.%s association has a configured autoload===true, this is forbidden for platform integrations', |
||
| 114 | $constant, |
||
| 115 | $propType->getValue() |
||
| 116 | ))->build(), |
||
| 117 | ]; |
||
| 118 | } |
||
| 119 | |||
| 120 | return []; |
||
| 121 | } |
||
| 123 |
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