Conditions | 7 |
Paths | 9 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
77 | private function chunk($line) |
||
78 | { |
||
79 | if (mb_strlen($line) <= $this->width) { |
||
80 | return [$line]; |
||
81 | } |
||
82 | $stripped = strip_tags($line); |
||
83 | $offset = 0; |
||
84 | $out = []; |
||
85 | |||
86 | // create a stripped tags version of the string |
||
87 | // loop through both and only move the counter if both characters are equal |
||
88 | // yield when we get to <width> for the stripped tags version |
||
89 | for ($i = 0, $j = 0; $i <= mb_strlen($stripped); $j++) { |
||
90 | if (mb_substr($stripped, $i, 1) === mb_substr($line, $j, 1)) { |
||
91 | if ($i >= $this->width && $i % $this->width == 0) { |
||
92 | $out[] = mb_substr($line, $offset, $j - $offset); |
||
93 | $offset = $j; |
||
94 | } |
||
95 | $i++; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | // return any remaining entries |
||
100 | if ($offset != $j - 1) { |
||
101 | $out[] = mb_substr($line, $offset); |
||
102 | } |
||
103 | return $out; |
||
104 | } |
||
105 | } |
||
106 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.