Conditions | 15 |
Paths | 75 |
Total Lines | 84 |
Code Lines | 51 |
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 |
||
123 | protected function execute(InputInterface $input, OutputInterface $output) |
||
124 | { |
||
125 | $questionHelper = $this->getHelper('question'); |
||
126 | $question = new ConfirmationQuestion('Are you sure you want to anonymize your database?', true); |
||
127 | |||
128 | if (!$questionHelper->ask($input, $output, $question)) { |
||
129 | return; |
||
130 | } |
||
131 | |||
132 | $em = null; |
||
133 | $connection = null; |
||
|
|||
134 | $configName = null; |
||
135 | |||
136 | |||
137 | try { |
||
138 | $connection = $this->getConnectionFromInput($input); |
||
139 | } catch (DBALException $e) { |
||
140 | $connection = null; |
||
141 | } |
||
142 | |||
143 | // Retrieve database connection. |
||
144 | if ($connection) { |
||
145 | $configName = 'default'; |
||
146 | } elseif ($emName = $input->getOption('em')) { |
||
147 | $em = $this->registry->getEntityManager($emName); |
||
148 | $connection = $em->getConnection(); |
||
149 | $configName = (string) $emName; |
||
150 | } else { |
||
151 | if (!$this->registry) { |
||
152 | throw new \LogicException('You must activete doctrine dbal component'); |
||
153 | } |
||
154 | |||
155 | $configName = $input->getOption('connection'); |
||
156 | if (!$configName) { |
||
157 | $configName = $this->registry->getDefaultConnectionName(); |
||
158 | } |
||
159 | |||
160 | $connection = $this->registry->getConnection($configName); |
||
161 | } |
||
162 | |||
163 | if (!$connection) { |
||
164 | throw new \LogicException('Cannot find or crete connection'); |
||
165 | } |
||
166 | |||
167 | // Retrieve anonymizer configuration. |
||
168 | if ($input->getOption('annotations')) { |
||
169 | if (!$em) { |
||
170 | $output->writeln('<error>You must pass entity manager name in "--em" option. Pass "--em=default" if there is only one entity manager.</error>'); |
||
171 | |||
172 | return; |
||
173 | } |
||
174 | |||
175 | if (!$this->annotationConfigFactory) { |
||
176 | $output->writeln('<error>You must enable Doctrine annotations: "annotations.reader" service is required.</error>'); |
||
177 | |||
178 | return; |
||
179 | } |
||
180 | |||
181 | $config = $this->annotationConfigFactory->getConfig($em->getMetadataFactory()->getAllMetadata()); |
||
182 | } elseif ($configFile = $input->getOption('config')) { |
||
183 | $configFilePath = realpath($input->getOption('config')); |
||
184 | if (!is_file($configFilePath)) { |
||
185 | $output->writeln(sprintf('<error>Configuration file "%s" does not exist.</error>', $configFile)); |
||
186 | |||
187 | return; |
||
188 | } |
||
189 | |||
190 | $config = $this->getConfigFromFile($configFilePath); |
||
191 | } elseif (!empty($this->defaultConfig)) { |
||
192 | if (!array_key_exists($configName, $this->defaultConfig['connections'])) { |
||
193 | throw new \LogicException('You must configure anonymizer for "'.$configName.'" connection'); |
||
194 | }; |
||
195 | |||
196 | $config = $this->defaultConfig['connections'][$configName]; |
||
197 | } else { |
||
198 | throw new \InvalidArgumentException('You must either provide the path of configuration file or confiqure the bundle or define annotations.'); |
||
199 | } |
||
200 | |||
201 | $targetFactory = new TargetFactory($this->generatorFactory); |
||
202 | $targetFactory->setConnection($connection); |
||
203 | $targetTables = $targetFactory->createTargets($config); |
||
204 | |||
205 | $anonymizer = new Anonymizer(); |
||
206 | $anonymizer->anonymize($connection, $targetTables); |
||
207 | } |
||
209 |