| Conditions | 7 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 33 |
| 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 |
||
| 91 | public function generateDocumentFiles(OutputInterface $output, BundleMetadata $bundleMetadata): void |
||
| 92 | { |
||
| 93 | $output->writeln(' - Generating Document files'); |
||
| 94 | |||
| 95 | $names = $bundleMetadata->getPhpcrMetadata()->getDocumentNames(); |
||
| 96 | |||
| 97 | foreach ($names as $name) { |
||
| 98 | $extendedName = $name; |
||
| 99 | |||
| 100 | $dest_file = sprintf( |
||
| 101 | '%s/%s.php', |
||
| 102 | $bundleMetadata->getPhpcrMetadata()->getExtendedDocumentDirectory(), |
||
| 103 | $name |
||
| 104 | ); |
||
| 105 | $src_file = sprintf( |
||
| 106 | '%s/%s.php', |
||
| 107 | $bundleMetadata->getPhpcrMetadata()->getDocumentDirectory(), |
||
| 108 | $extendedName |
||
| 109 | ); |
||
| 110 | |||
| 111 | if (!is_file($src_file)) { |
||
| 112 | $extendedName = 'Base'.$name; |
||
| 113 | $src_file = sprintf( |
||
| 114 | '%s/%s.php', |
||
| 115 | $bundleMetadata->getPhpcrMetadata()->getDocumentDirectory(), |
||
| 116 | $extendedName |
||
| 117 | ); |
||
| 118 | |||
| 119 | if (!is_file($src_file)) { |
||
| 120 | $output->writeln(sprintf(' ! <info>%s</info>', $extendedName)); |
||
| 121 | |||
| 122 | continue; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if (is_file($dest_file)) { |
||
| 127 | $output->writeln(sprintf(' ~ <info>%s</info>', $name)); |
||
| 128 | } else { |
||
| 129 | $output->writeln(sprintf(' + <info>%s</info>', $name)); |
||
| 130 | |||
| 131 | $string = Mustache::replace($this->getDocumentTemplate(), array( |
||
| 132 | 'extended_namespace' => $bundleMetadata->getExtendedNamespace(), |
||
| 133 | 'name' => $name != $extendedName ? $extendedName : $name, |
||
| 134 | 'class' => $name, |
||
| 135 | 'extended_name' => $name == $extendedName ? 'Base'.$name : $extendedName, |
||
| 136 | 'namespace' => $bundleMetadata->getNamespace(), |
||
| 137 | )); |
||
| 138 | |||
| 139 | file_put_contents($dest_file, $string); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 204 |