| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 15 | public function generate(CommandArguments $commandArguments, string $filename, bool $withShortName = false): string |
|
| 27 | { |
||
| 28 | 15 | $this->fileContentIo->mkdir($commandArguments->directory()); |
|
| 29 | 15 | ||
| 30 | $moduleName = $withShortName ? '' : $commandArguments->basename(); |
||
| 31 | 15 | $className = $moduleName . $filename; |
|
| 32 | 15 | ||
| 33 | 15 | $path = sprintf('%s/%s.php', $commandArguments->directory(), $className); |
|
| 34 | $search = ['$NAMESPACE$', '$MODULE_NAME$', '$CLASS_NAME$']; |
||
| 35 | 15 | $replace = [$commandArguments->namespace(), $moduleName, $className]; |
|
| 36 | 15 | ||
| 37 | 1 | $template = $this->templateByFilenameMap[$filename] ?? ''; |
|
| 38 | if ($template === '') { |
||
| 39 | throw new RuntimeException(sprintf("Unknown template for '%s'?", $filename)); |
||
| 40 | 14 | } |
|
| 41 | |||
| 42 | 14 | $fileContent = str_replace($search, $replace, $template); |
|
| 43 | |||
| 44 | 14 | $this->fileContentIo->filePutContents($path, $fileContent); |
|
| 45 | |||
| 46 | return $path; |
||
| 47 | } |
||
| 49 |