Conditions | 11 |
Paths | 114 |
Total Lines | 75 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
87 | protected function execute(InputInterface $input, OutputInterface $output) |
||
88 | { |
||
89 | $em = $this->getHelper('em')->getEntityManager(); |
||
90 | |||
91 | if ($input->getOption('from-database') === true) { |
||
92 | $databaseDriver = new DatabaseDriver( |
||
93 | $em->getConnection()->getSchemaManager() |
||
94 | ); |
||
95 | |||
96 | $em->getConfiguration()->setMetadataDriverImpl( |
||
97 | $databaseDriver |
||
98 | ); |
||
99 | |||
100 | if (($namespace = $input->getOption('namespace')) !== null) { |
||
101 | $databaseDriver->setNamespace($namespace); |
||
102 | } |
||
103 | } |
||
104 | $doctrineMetaData = $this->getMetaData($em, $input); |
||
105 | |||
106 | // Process destination directory |
||
107 | if (!is_dir($destPath = $input->getArgument('dest-path'))) { |
||
108 | mkdir($destPath, 0777, true); |
||
109 | } |
||
110 | $destPath = realpath($destPath); |
||
111 | |||
112 | if (!file_exists($destPath)) { |
||
113 | throw new \InvalidArgumentException( |
||
114 | sprintf( |
||
115 | "Destination directory '<info>%s</info>' does not exist.", |
||
116 | $input->getArgument('dest-path') |
||
117 | ) |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | if (!is_writable($destPath)) { |
||
122 | throw new \InvalidArgumentException( |
||
123 | sprintf( |
||
124 | "Destination directory '<info>%s</info>' does not have write permissions.", |
||
125 | $destPath |
||
126 | ) |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | if (0 === count($doctrineMetaData)) { |
||
131 | $output->writeln('No Metadata Classes to process.'); |
||
132 | return; |
||
133 | } |
||
134 | $generator = $this->getGenerator(); |
||
135 | |||
136 | if (($extend = $input->getOption('extend')) !== null) { |
||
137 | $generator->setClassToExtend($extend); |
||
138 | } |
||
139 | |||
140 | if (($namespace = $input->getOption('namespace')) !== null) { |
||
141 | $generator->setNamespace($namespace); |
||
142 | } |
||
143 | if (($numSpaces = $input->getOption('num-spaces')) !== null) { |
||
144 | $generator->setNumSpaces($numSpaces); |
||
145 | } |
||
146 | |||
147 | $metaData = array(); |
||
148 | $hydtrator = $this->getHydrator(); |
||
149 | |||
150 | foreach ($doctrineMetaData as $data) { |
||
151 | $metaData[$data->name] = new MetadataInfo($hydtrator->extract($data)); |
||
152 | $output->writeln( |
||
153 | sprintf('Processing class "<info>%s</info>"', $data->name) |
||
154 | ); |
||
155 | } |
||
156 | |||
157 | $generator->generate($metaData, $destPath); |
||
158 | |||
159 | // Outputting information message |
||
160 | $output->writeln(PHP_EOL . sprintf('Classes generated to "<info>%s</INFO>"', $destPath)); |
||
161 | } |
||
162 | |||
194 |