| Conditions | 2 |
| Paths | 2 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 5 |
| Ratio | 22.73 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function includeFile(string $directory, string $filename): string |
||
| 43 | { |
||
| 44 | if (!file_exists("$directory/$filename")) { |
||
| 45 | throw new DocuGeneratorException( |
||
| 46 | sprintf("Can not include non-existing file %s/%s", $directory, $filename) |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | $includeContent = file_get_contents("$directory/$filename"); |
||
| 51 | |||
| 52 | $includeContent = preg_replace_callback( |
||
| 53 | self::INCLUDE_PATTERN, |
||
| 54 | View Code Duplication | function(array $input) use ($directory): string { |
|
| 55 | $dir = $directory . '/' . dirname($input[1]); |
||
| 56 | |||
| 57 | return $this->includeFile($dir, basename($input[1])); |
||
| 58 | }, |
||
| 59 | $includeContent |
||
| 60 | ); |
||
| 61 | |||
| 62 | return $includeContent; |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
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.