We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 11 |
| Paths | 27 |
| Total Lines | 53 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 132 |
| 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 |
||
| 67 | public function getFullMessage(): Message |
||
| 68 | { |
||
| 69 | $messages = ['- '.$this->factory->message($this->result)->__toString()]; |
||
| 70 | $iterator = new RecursiveIteratorIterator( |
||
| 71 | new ResultRecursiveIterator($this->result), |
||
| 72 | RecursiveIteratorIterator::SELF_FIRST |
||
| 73 | ); |
||
| 74 | $lastDepth = 0; |
||
| 75 | $lastDepthOriginal = 0; |
||
| 76 | $lastStringKey = null; |
||
| 77 | $knownDepths = []; |
||
| 78 | /* @var Result $childResult */ |
||
| 79 | foreach ($iterator as $childKey => $childResult) { |
||
| 80 | $message = $this->factory->message($childResult); |
||
| 81 | $childrenCount = \count($iterator->callGetChildren()); |
||
| 82 | |||
| 83 | if ($childrenCount == 1) { |
||
| 84 | $lastStringKey = is_string($childKey) ? $childKey : null; |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | $currentDepth = $lastDepth; |
||
| 89 | $currentDepthOriginal = $iterator->getDepth() + 1; |
||
| 90 | |||
| 91 | if (isset($knownDepths[$currentDepthOriginal])) { |
||
| 92 | $currentDepth = $knownDepths[$currentDepthOriginal]; |
||
| 93 | } elseif ($currentDepthOriginal > $lastDepthOriginal && $childrenCount != 1) { |
||
| 94 | ++$currentDepth; |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!isset($knownDepths[$currentDepthOriginal])) { |
||
| 98 | $knownDepths[$currentDepthOriginal] = $currentDepth; |
||
| 99 | } |
||
| 100 | |||
| 101 | $lastDepth = $currentDepth; |
||
| 102 | $lastDepthOriginal = $currentDepthOriginal; |
||
| 103 | |||
| 104 | $placeholder = null; |
||
| 105 | if ($lastDepth <= $currentDepth && is_string($lastStringKey)) { |
||
| 106 | $placeholder = sprintf('"%s"', $lastStringKey); |
||
| 107 | } |
||
| 108 | |||
| 109 | $messages[] = \sprintf( |
||
| 110 | '%s- %s', |
||
| 111 | \str_repeat(' ', $currentDepth * 2), |
||
| 112 | $message->render($placeholder) |
||
| 113 | ); |
||
| 114 | |||
| 115 | $lastStringKey = is_string($childKey) ? $childKey : null; |
||
| 116 | } |
||
| 117 | |||
| 118 | return new Message('Validation', \implode(PHP_EOL, $messages), $this->result->getInput()); |
||
| 119 | } |
||
| 120 | |||
| 153 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: