These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Doctrine\ODM\MongoDB\Tools\Console\Command; |
||
4 | |||
5 | use Symfony\Component\Console\Input\InputArgument; |
||
6 | use Symfony\Component\Console\Input\InputOption; |
||
7 | use Symfony\Component\Console; |
||
8 | use Doctrine\ODM\MongoDB\Tools\Console\MetadataFilter; |
||
9 | |||
10 | /** |
||
11 | * Command to (re)generate the hydrator classes used by doctrine. |
||
12 | * |
||
13 | * @since 1.0 |
||
14 | */ |
||
15 | class GenerateHydratorsCommand extends Console\Command\Command |
||
16 | { |
||
17 | /** |
||
18 | * @see Console\Command\Command |
||
19 | */ |
||
20 | View Code Duplication | protected function configure() |
|
0 ignored issues
–
show
|
|||
21 | { |
||
22 | $this |
||
23 | ->setName('odm:generate:hydrators') |
||
24 | ->setDescription('Generates hydrator classes for document classes.') |
||
25 | ->setDefinition(array( |
||
26 | new InputOption( |
||
27 | 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
||
28 | 'A string pattern used to match documents that should be processed.' |
||
29 | ), |
||
30 | new InputArgument( |
||
31 | 'dest-path', InputArgument::OPTIONAL, |
||
32 | 'The path to generate your hydrator classes. If none is provided, it will attempt to grab from configuration.' |
||
33 | ), |
||
34 | )) |
||
35 | ->setHelp(<<<EOT |
||
36 | Generates hydrator classes for document classes. |
||
37 | EOT |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @see Console\Command\Command |
||
43 | */ |
||
44 | protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) |
||
45 | { |
||
46 | $dm = $this->getHelper('documentManager')->getDocumentManager(); |
||
47 | |||
48 | $metadatas = $dm->getMetadataFactory()->getAllMetadata(); |
||
49 | $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); |
||
50 | |||
51 | // Process destination directory |
||
52 | if (($destPath = $input->getArgument('dest-path')) === null) { |
||
53 | $destPath = $dm->getConfiguration()->getHydratorDir(); |
||
54 | } |
||
55 | |||
56 | if ( ! is_dir($destPath)) { |
||
57 | mkdir($destPath, 0775, true); |
||
58 | } |
||
59 | |||
60 | $destPath = realpath($destPath); |
||
61 | |||
62 | View Code Duplication | if ( ! file_exists($destPath)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
63 | throw new \InvalidArgumentException( |
||
64 | sprintf("Hydrators destination directory '<info>%s</info>' does not exist.", $destPath) |
||
65 | ); |
||
66 | } elseif ( ! is_writable($destPath)) { |
||
67 | throw new \InvalidArgumentException( |
||
68 | sprintf("Hydrators destination directory '<info>%s</info>' does not have write permissions.", $destPath) |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | View Code Duplication | if (count($metadatas)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
73 | foreach ($metadatas as $metadata) { |
||
74 | $output->write( |
||
75 | sprintf('Processing document "<info>%s</info>"', $metadata->name) . PHP_EOL |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | // Generating Hydrators |
||
80 | $dm->getHydratorFactory()->generateHydratorClasses($metadatas, $destPath); |
||
81 | |||
82 | // Outputting information message |
||
83 | $output->write(PHP_EOL . sprintf('Hydrator classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); |
||
84 | } else { |
||
85 | $output->write('No Metadata Classes to process.' . PHP_EOL); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.