| 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 | $fileNameAsString = $projectRoot->getPathRelativeToRootDirectory($absoluteFilePath); |
||
| 103 | $fileName = new FileName($fileNameAsString); |
||
| 104 | |||
| 105 | $messages = ArrayUtils::getArrayValue($fileErrors, self::MESSAGES); |
||
| 106 | |||
| 107 | foreach ($messages as $message) { |
||
| 108 | ArrayUtils::assertArray($message); |
||
| 109 | $analysisResult = $this->convertAnalysisResultFromArray($message, $fileName, $absoluteFilePath); |
||
| 110 | $analysisResults->addAnalysisResult($analysisResult); |
||
| 111 | } |
||
| 112 | } catch (ArrayParseException | JsonParseException | InvalidPathException $e) { |
||
| 113 | throw new ParseAtLocationException("Result [$absoluteFilePath]", $e); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | return $analysisResults; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @phpstan-param array<mixed> $analysisResultAsArray |
||
| 122 | * |
||
| 123 | * @throws ArrayParseException |
||
| 124 | * @throws JsonParseException |
||
| 125 | */ |
||
| 126 | private function convertAnalysisResultFromArray( |
||
| 127 | array $analysisResultAsArray, |
||
| 128 | FileName $fileName, |
||
| 129 | string $absoluteFilePath |
||
| 130 | ): AnalysisResult { |
||
| 131 | $lineAsInt = ArrayUtils::getIntValue($analysisResultAsArray, self::LINE); |
||
| 132 | $rawMessage = ArrayUtils::getStringValue($analysisResultAsArray, self::MESSAGE); |
||
| 133 | $rawSource = ArrayUtils::getStringValue($analysisResultAsArray, self::SOURCE); |
||
| 134 | |||
| 135 | $location = new Location( |
||
| 136 | $fileName, |
||
| 137 | new LineNumber($lineAsInt) |
||
| 138 | ); |
||
| 139 | |||
| 140 | return new AnalysisResult( |
||
| 151 |