| Conditions | 12 |
| Paths | 24 |
| Total Lines | 52 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 37 |
| CRAP Score | 12 |
| 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 |
||
| 42 | 1 | public function process(File $file, CodeElementInterface $prop): void |
|
| 43 | { |
||
| 44 | // @TODO Infer type from initial value? |
||
| 45 | 1 | $docBlock = $prop->getDocBlock(); |
|
| 46 | |||
| 47 | /** @var VarTag|null $varTag */ |
||
| 48 | 1 | $varTag = $docBlock->getTagsByName('var')[0] ?? null; |
|
| 49 | 1 | $docType = $varTag ? $varTag->getType() : null; |
|
| 50 | |||
| 51 | 1 | $subject = 'property $'.$prop->getPropName(); |
|
|
1 ignored issue
–
show
|
|||
| 52 | |||
| 53 | 1 | if ($docBlock instanceof UndefinedDocBlock) { |
|
| 54 | 1 | $file->addWarningOnLine( |
|
| 55 | 1 | 'Add PHPDoc for '.$subject, |
|
| 56 | 1 | $prop->getLine(), |
|
| 57 | 1 | 'FqcnPropSniff' |
|
| 58 | ); |
||
| 59 | 1 | } elseif (null === $varTag) { |
|
| 60 | 1 | $file->addWarningOnLine( |
|
| 61 | 1 | 'Add @var tag for '.$subject, |
|
| 62 | 1 | $prop->getLine(), |
|
| 63 | 1 | 'FqcnPropSniff' |
|
| 64 | ); |
||
| 65 | 1 | } elseif ($docType instanceof UndefinedType) { |
|
| 66 | 1 | $file->addWarningOnLine( |
|
| 67 | 1 | 'Add type hint to @var tag for '.$subject, |
|
| 68 | 1 | $prop->getLine(), |
|
| 69 | 1 | 'FqcnPropSniff' |
|
| 70 | ); |
||
| 71 | 1 | } elseif ($docType instanceof ArrayType |
|
| 72 | 1 | || ($docType instanceof CompoundType && $docType->containsType(ArrayType::class)) |
|
| 73 | ) { |
||
| 74 | 1 | $file->addWarningOnLine( |
|
| 75 | 1 | 'Replace array type with typed array type in PHPDoc for '.$subject.'. Use mixed[] for generic arrays.', |
|
| 76 | 1 | $prop->getLine(), |
|
| 77 | 1 | 'FqcnPropSniff' |
|
| 78 | ); |
||
| 79 | 1 | } elseif (is_a($prop->getDefaultValueType(), ArrayType::class) |
|
|
1 ignored issue
–
show
|
|||
| 80 | 1 | && !is_a($docType, TypedArrayType::class) |
|
| 81 | ) { |
||
| 82 | 1 | $file->addWarningOnLine( |
|
| 83 | 1 | 'Add PHPDoc with typed array type hint for '.$subject.'. Use mixed[] for generic arrays.', |
|
| 84 | 1 | $prop->getLine(), |
|
| 85 | 1 | 'FqcnPropSniff' |
|
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | 1 | if ($varTag && null !== $varTag->getParamName()) { |
|
| 90 | 1 | $file->addWarningOnLine( |
|
| 91 | 1 | 'Remove property name $'.$varTag->getParamName().' from @var tag', |
|
| 92 | 1 | $prop->getLine(), |
|
| 93 | 1 | 'FqcnPropSniff' |
|
| 94 | ); |
||
| 98 |