| Conditions | 10 |
| Paths | 28 |
| Total Lines | 54 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 62 | protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) |
||
| 63 | { |
||
| 64 | $dm = $this->getHelper('documentManager')->getDocumentManager(); |
||
| 65 | |||
| 66 | $metadatas = $dm->getMetadataFactory()->getAllMetadata(); |
||
| 67 | $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); |
||
| 68 | |||
| 69 | // Process destination directory |
||
| 70 | if (($destPath = $input->getArgument('dest-path')) === null) { |
||
| 71 | $destPath = $dm->getConfiguration()->getPersistentCollectionDir(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ( ! is_dir($destPath)) { |
||
| 75 | mkdir($destPath, 0775, true); |
||
| 76 | } |
||
| 77 | |||
| 78 | $destPath = realpath($destPath); |
||
| 79 | |||
| 80 | if ( ! file_exists($destPath)) { |
||
| 81 | throw new \InvalidArgumentException( |
||
| 82 | sprintf("Persistent collections destination directory '<info>%s</info>' does not exist.", $destPath) |
||
| 83 | ); |
||
| 84 | } elseif ( ! is_writable($destPath)) { |
||
| 85 | throw new \InvalidArgumentException( |
||
| 86 | sprintf("Persistent collections destination directory '<info>%s</info>' does not have write permissions.", $destPath) |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if (count($metadatas)) { |
||
| 91 | $generated = []; |
||
| 92 | $collectionGenerator = $dm->getConfiguration()->getPersistentCollectionGenerator(); |
||
| 93 | foreach ($metadatas as $metadata) { |
||
| 94 | $output->write( |
||
| 95 | sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL |
||
| 96 | ); |
||
| 97 | foreach ($metadata->getAssociationNames() as $fieldName) { |
||
| 98 | $mapping = $metadata->getFieldMapping($fieldName); |
||
| 99 | if (empty($mapping['collectionClass']) || isset($generated[$mapping['collectionClass']])) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | $generated[$mapping['collectionClass']] = true; |
||
| 103 | $output->write( |
||
| 104 | sprintf('Generating class for "<info>%s</info>"', $mapping['collectionClass']) . PHP_EOL |
||
| 105 | ); |
||
| 106 | $collectionGenerator->generateClass($mapping['collectionClass'], $destPath); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | // Outputting information message |
||
| 111 | $output->write(PHP_EOL . sprintf('Persistent collections classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); |
||
| 112 | } else { |
||
| 113 | $output->write('No Metadata Classes to process.' . PHP_EOL); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 |