| Total Complexity | 52 |
| Total Lines | 192 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like MaskPatternTester often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MaskPatternTester, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | final class MaskPatternTester{ |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The data interface that contains the data matrix to test |
||
| 30 | */ |
||
| 31 | protected QRDataInterface $dataInterface; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Receives the QRDataInterface |
||
| 35 | * |
||
| 36 | * @see \chillerlan\QRCode\QROptions::$maskPattern |
||
| 37 | * @see \chillerlan\QRCode\Data\QRMatrix::$maskPattern |
||
| 38 | */ |
||
| 39 | public function __construct(QRDataInterface $dataInterface){ |
||
| 40 | $this->dataInterface = $dataInterface; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * shoves a QRMatrix through the MaskPatternTester to find the lowest penalty mask pattern |
||
| 45 | * |
||
| 46 | * @see \chillerlan\QRCode\Data\MaskPatternTester |
||
| 47 | */ |
||
| 48 | public function getBestMaskPattern():int{ |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the penalty for the given mask pattern |
||
| 60 | * |
||
| 61 | * @see \chillerlan\QRCode\QROptions::$maskPattern |
||
| 62 | * @see \chillerlan\QRCode\Data\QRMatrix::$maskPattern |
||
| 63 | */ |
||
| 64 | public function testPattern(int $pattern):int{ |
||
| 65 | $matrix = $this->dataInterface->initMatrix($pattern, true); |
||
| 66 | $penalty = 0; |
||
| 67 | |||
| 68 | for($level = 1; $level <= 4; $level++){ |
||
| 69 | $penalty += call_user_func_array([$this, 'testLevel'.$level], [$matrix, $matrix->size()]); |
||
| 70 | } |
||
| 71 | |||
| 72 | return (int)$penalty; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Checks for each group of five or more same-colored modules in a row (or column) |
||
| 77 | */ |
||
| 78 | protected function testLevel1(QRMatrix $m, int $size):float{ |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Checks for each 2x2 area of same-colored modules in the matrix |
||
| 116 | */ |
||
| 117 | protected function testLevel2(QRMatrix $m, int $size):float{ |
||
| 118 | $penalty = 0; |
||
| 119 | |||
| 120 | foreach($m->matrix() as $y => $row){ |
||
| 121 | |||
| 122 | if($y > $size - 2){ |
||
| 123 | break; |
||
| 124 | } |
||
| 125 | |||
| 126 | foreach($row as $x => $val){ |
||
| 127 | |||
| 128 | if($x > $size - 2){ |
||
| 129 | break; |
||
| 130 | } |
||
| 131 | |||
| 132 | $count = 0; |
||
| 133 | |||
| 134 | if($val >> 8 > 0){ |
||
| 135 | $count++; |
||
| 136 | } |
||
| 137 | |||
| 138 | if($m->check($y, $x + 1)){ |
||
| 139 | $count++; |
||
| 140 | } |
||
| 141 | |||
| 142 | if($m->check($y + 1, $x)){ |
||
| 143 | $count++; |
||
| 144 | } |
||
| 145 | |||
| 146 | if($m->check($y + 1, $x + 1)){ |
||
| 147 | $count++; |
||
| 148 | } |
||
| 149 | |||
| 150 | if($count === 0 || $count === 4){ |
||
| 151 | $penalty += 3; |
||
| 152 | } |
||
| 153 | |||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | return $penalty; |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Checks if there are patterns that look similar to the finder patterns (1:1:3:1:1 ratio) |
||
| 162 | */ |
||
| 163 | protected function testLevel3(QRMatrix $m, int $size):float{ |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Checks if more than half of the modules are dark or light, with a larger penalty for a larger difference |
||
| 205 | */ |
||
| 206 | protected function testLevel4(QRMatrix $m, int $size):float{ |
||
| 218 | } |
||
| 219 | |||
| 220 | } |
||
| 221 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths