| Conditions | 12 |
| Paths | 76 |
| Total Lines | 64 |
| Code Lines | 40 |
| 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 |
||
| 86 | public function table(): string |
||
| 87 | { |
||
| 88 | $ranking = $this->benchmark->getMatrix()->ranking(); |
||
| 89 | $matrix = $this->benchmark->getMatrix()->matrix(); |
||
| 90 | |||
| 91 | if (!$ranking) { |
||
|
|
|||
| 92 | return ''; |
||
| 93 | } |
||
| 94 | |||
| 95 | $columnLength = []; |
||
| 96 | $maxLength = 0; |
||
| 97 | |||
| 98 | foreach ($ranking as $task) { |
||
| 99 | $name = $task->name(); |
||
| 100 | |||
| 101 | if (\preg_match('~^([\w\s]+)~', $name, $matches)) { |
||
| 102 | $columnLength[$name] = \mb_strlen(\trim($matches[1])); |
||
| 103 | } else { |
||
| 104 | $columnLength[$name] = \mb_strlen($name); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (\mb_strlen($name) > $maxLength) { |
||
| 108 | $maxLength = \mb_strlen($name); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $result = ''; |
||
| 113 | $result .= $this->strPad('', $maxLength); |
||
| 114 | $result .= $this->strPad('Rate', 10); |
||
| 115 | $result .= $this->strPad('Mem', 8); |
||
| 116 | |||
| 117 | foreach ($ranking as $task) { |
||
| 118 | $name = $task->name(); |
||
| 119 | |||
| 120 | if (\preg_match('~^([\w\s]+)~', $name, $matches)) { |
||
| 121 | $result .= $this->strPad(\trim($matches[1]), $columnLength[$name] + 2); |
||
| 122 | } else { |
||
| 123 | $result .= $this->strPad($name, $columnLength[$name] + 2); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $result .= "\n"; |
||
| 127 | |||
| 128 | foreach ($ranking as $task1) { |
||
| 129 | $name1 = $task1->name(); |
||
| 130 | $result .= $this->strPad($name1, $maxLength, ' ', \STR_PAD_RIGHT); |
||
| 131 | $task1 = $this->_benchmark->task($name1); |
||
| 132 | |||
| 133 | $result .= $this->strPad($this->readableSize($task1->rate()) . '/s', 10); |
||
| 134 | $result .= $this->strPad($this->readableSize($task1->memory(), 0, 1024) . 'B', 8); |
||
| 135 | |||
| 136 | foreach ($ranking as $task2) { |
||
| 137 | $name2 = $task2->name(); |
||
| 138 | |||
| 139 | if ($task1->failed() || $task2->failed()) { |
||
| 140 | $result .= $this->strPad('x', $columnLength[$name2] + 2); |
||
| 141 | } else { |
||
| 142 | $percent = $matrix[$name1][$name2] !== 100 ? $matrix[$name1][$name2] : '--'; |
||
| 143 | $result .= $this->strPad($percent . '%', $columnLength[$name2] + 2); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | $result .= "\n"; |
||
| 147 | } |
||
| 148 | |||
| 149 | return $result; |
||
| 150 | } |
||
| 212 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.