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