| Conditions | 4 | 
| Paths | 6 | 
| Total Lines | 77 | 
| Code Lines | 46 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| 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 | ||
| 63 | public function getIdentifier(): Identifier | ||
| 64 |     { | ||
| 65 | return new PhpCodeSnifferJsonIdentifier(); | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 |      * {@inheritdoc} | ||
| 70 | */ | ||
| 71 | public function showTypeGuessingWarning(): bool | ||
| 72 |     { | ||
| 73 | return false; | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Converts from an array. | ||
| 78 | * | ||
| 79 | * @phpstan-param array<mixed> $analysisResultsAsArray | ||
| 80 | * | ||
| 81 | * @throws ParseAtLocationException | ||
| 82 | */ | ||
| 83 | private function convertFromArray(array $analysisResultsAsArray, ProjectRoot $projectRoot): AnalysisResults | ||
| 84 |     { | ||
| 85 | $analysisResults = new AnalysisResults(); | ||
| 86 | |||
| 87 |         try { | ||
| 88 | $filesErrors = ArrayUtils::getArrayValue($analysisResultsAsArray, self::FILES); | ||
| 89 |         } catch (ArrayParseException $e) { | ||
| 90 |             throw new ParseAtLocationException('Root node', $e); | ||
| 91 | } | ||
| 92 | |||
| 93 | /** @psalm-suppress MixedAssignment */ | ||
| 94 |         foreach ($filesErrors as $absoluteFilePath => $fileErrors) { | ||
| 95 |             try { | ||
| 96 |                 if (!is_string($absoluteFilePath)) { | ||
| 97 |                     throw new ArrayParseException('Expected filename to be of type string'); | ||
| 98 | } | ||
| 99 | |||
| 100 | ArrayUtils::assertArray($fileErrors); | ||
| 101 | |||
| 102 | $errorsCount = ArrayUtils::getIntValue($fileErrors, self::ERRORS); | ||
| 103 | $warningsCount = ArrayUtils::getIntValue($fileErrors, self::WARNINGS); | ||
| 104 |                 if (0 === $errorsCount && 0 === $warningsCount) { | ||
| 105 | continue; | ||
| 106 | } | ||
| 107 | |||
| 108 | $fileNameAsString = $projectRoot->getPathRelativeToRootDirectory($absoluteFilePath); | ||
| 109 | $fileName = new FileName($fileNameAsString); | ||
| 110 | |||
| 111 | $messages = ArrayUtils::getArrayValue($fileErrors, self::MESSAGES); | ||
| 112 | |||
| 113 |                 foreach ($messages as $message) { | ||
| 114 | ArrayUtils::assertArray($message); | ||
| 115 | $analysisResult = $this->convertAnalysisResultFromArray($message, $fileName, $absoluteFilePath); | ||
| 116 | $analysisResults->addAnalysisResult($analysisResult); | ||
| 117 | } | ||
| 118 |             } catch (ArrayParseException | JsonParseException | InvalidPathException $e) { | ||
| 119 |                 throw new ParseAtLocationException("Result [$absoluteFilePath]", $e); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | return $analysisResults; | ||
| 124 | } | ||
| 125 | |||
| 126 | /** | ||
| 127 | * @phpstan-param array<mixed> $analysisResultAsArray | ||
| 128 | * | ||
| 129 | * @throws ArrayParseException | ||
| 130 | * @throws JsonParseException | ||
| 131 | */ | ||
| 132 | private function convertAnalysisResultFromArray( | ||
| 133 | array $analysisResultAsArray, | ||
| 134 | FileName $fileName, | ||
| 135 | string $absoluteFilePath | ||
| 136 |     ): AnalysisResult { | ||
| 137 | $lineAsInt = ArrayUtils::getIntValue($analysisResultAsArray, self::LINE); | ||
| 138 | $rawMessage = ArrayUtils::getStringValue($analysisResultAsArray, self::MESSAGE); | ||
| 139 | $rawSource = ArrayUtils::getStringValue($analysisResultAsArray, self::SOURCE); | ||
| 140 | |||
| 157 |