| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 3 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 11 | 6 | public function fix(Result $result): bool |
|
| 12 | { |
||
| 13 | 6 | if ($result->isValid()) { |
|
| 14 | 2 | return false; |
|
| 15 | } |
||
| 16 | |||
| 17 | 4 | $actualNamespacePattern = '/namespace ' . preg_quote($result->getActual()) . '/'; |
|
| 18 | |||
| 19 | 4 | if (Regex::matchAll($actualNamespacePattern, $result->getFile()->getContents())->hasMatch()) { |
|
| 20 | 3 | $pattern = $actualNamespacePattern; |
|
| 21 | 3 | $replacement = 'namespace ' . $result->getExpected(); |
|
| 22 | } else { |
||
| 23 | 1 | $pattern = '/<\?php/'; |
|
| 24 | 1 | $replacement = "<?php\n\nnamespace " . $result->getExpected() . ';'; |
|
| 25 | } |
||
| 26 | |||
| 27 | 4 | $content = Regex::replace($pattern, $replacement, $result->getFile()->getContents())->result(); |
|
| 28 | |||
| 29 | $result |
||
| 30 | 4 | ->getFile() |
|
| 31 | 4 | ->openFile('w') |
|
| 32 | 4 | ->fwrite(strval($content)); |
|
| 33 | |||
| 34 | 4 | return true; |
|
| 35 | } |
||
| 37 |