| Conditions | 6 |
| Paths | 12 |
| Total Lines | 68 |
| Code Lines | 36 |
| 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 |
||
| 63 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 64 | { |
||
| 65 | $destination = $input->getOption('output'); |
||
| 66 | $metaDataEntries = $this->entityManager->getMetadataFactory()->getAllMetadata(); |
||
| 67 | |||
| 68 | if (!is_dir($destination)) { |
||
|
|
|||
| 69 | mkdir($destination, 0777, true); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** @var ClassMetadata $metaData */ |
||
| 73 | foreach ($metaDataEntries as $metaData) { |
||
| 74 | if ($filter = $input->getOption('filter')) { |
||
| 75 | if (strpos($metaData->getName(), $filter) === false) { |
||
| 76 | $output->writeln( |
||
| 77 | sprintf( |
||
| 78 | 'Filtering out %s...', |
||
| 79 | $metaData->getName() |
||
| 80 | ), |
||
| 81 | OutputInterface::VERBOSITY_VERY_VERBOSE |
||
| 82 | ); |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $fileName = $destination . '/' . $metaData->reflClass->getShortName() . 'DataFactory.php'; |
||
| 88 | // TODO handle duplicate names |
||
| 89 | |||
| 90 | $file = FileGenerator::fromArray( |
||
| 91 | [ |
||
| 92 | 'docblock' => DocBlockGenerator::fromArray( |
||
| 93 | [ |
||
| 94 | 'shortDescription' => '', |
||
| 95 | 'longDescription' => '', |
||
| 96 | 'tags' => [ |
||
| 97 | [ |
||
| 98 | 'name' => 'var', |
||
| 99 | 'description' => '\\Codeception\\Module\\DataFactory $factory' |
||
| 100 | ], |
||
| 101 | [ |
||
| 102 | 'name' => 'var', |
||
| 103 | 'description' => '\\Doctrine\\ORM\\EntityManager $em' |
||
| 104 | ] |
||
| 105 | ] |
||
| 106 | ] |
||
| 107 | ), |
||
| 108 | 'body' => $this->buildBody($metaData), |
||
| 109 | ] |
||
| 110 | ); |
||
| 111 | |||
| 112 | if (file_exists($fileName)) { |
||
| 113 | $output->writeln( |
||
| 114 | sprintf( |
||
| 115 | '%s already exists. Skipping...', |
||
| 116 | $fileName |
||
| 117 | ), |
||
| 118 | OutputInterface::VERBOSITY_VERBOSE |
||
| 119 | ); |
||
| 120 | |||
| 121 | continue; |
||
| 122 | } |
||
| 123 | |||
| 124 | file_put_contents($fileName, $file->generate()); |
||
| 125 | } |
||
| 126 | |||
| 127 | $output->writeln( |
||
| 128 | sprintf( |
||
| 129 | 'Data factories written to "%s"', |
||
| 130 | $destination |
||
| 131 | ) |
||
| 284 | } |