| Conditions | 6 |
| Paths | 6 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 85 | public function generateDocumentFiles(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
| 86 | { |
||
| 87 | $output->writeln(' - Generating Document files'); |
||
| 88 | |||
| 89 | $names = $bundleMetadata->getPhpcrMetadata()->getDocumentNames(); |
||
| 90 | |||
| 91 | foreach ($names as $name) { |
||
| 92 | $extendedName = $name; |
||
| 93 | |||
| 94 | $dest_file = sprintf( |
||
| 95 | '%s/%s.php', |
||
| 96 | $bundleMetadata->getPhpcrMetadata()->getExtendedDocumentDirectory(), |
||
| 97 | $name |
||
| 98 | ); |
||
| 99 | $src_file = sprintf( |
||
| 100 | '%s/%s.php', |
||
| 101 | $bundleMetadata->getPhpcrMetadata()->getDocumentDirectory(), |
||
| 102 | $extendedName |
||
| 103 | ); |
||
| 104 | |||
| 105 | if (!is_file($src_file)) { |
||
| 106 | $extendedName = 'Base'.$name; |
||
| 107 | $src_file = sprintf( |
||
| 108 | '%s/%s.php', |
||
| 109 | $bundleMetadata->getPhpcrMetadata()->getDocumentDirectory(), |
||
| 110 | $extendedName |
||
| 111 | ); |
||
| 112 | |||
| 113 | if (!is_file($src_file)) { |
||
| 114 | $output->writeln(sprintf(' ! <info>%s</info>', $extendedName)); |
||
| 115 | |||
| 116 | continue; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | if (is_file($dest_file)) { |
||
| 121 | $output->writeln(sprintf(' ~ <info>%s</info>', $name)); |
||
| 122 | } else { |
||
| 123 | $output->writeln(sprintf(' + <info>%s</info>', $name)); |
||
| 124 | |||
| 125 | $string = Mustache::replace($this->getDocumentTemplate(), [ |
||
| 126 | 'extended_namespace' => $bundleMetadata->getExtendedNamespace(), |
||
| 127 | 'name' => $extendedName, |
||
| 128 | 'class' => $name, |
||
| 129 | 'extended_name' => $name === $extendedName ? 'Base'.$name : $extendedName, |
||
| 130 | 'namespace' => $bundleMetadata->getNamespace(), |
||
| 131 | ]); |
||
| 132 | |||
| 133 | file_put_contents($dest_file, $string); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 188 |