| Conditions | 8 |
| Paths | 10 |
| Total Lines | 80 |
| 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 |
||
| 35 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 36 | { |
||
| 37 | if (!$this->lock()) { |
||
| 38 | $output->writeln('The command is already running in another process.'); |
||
| 39 | |||
| 40 | return 0; |
||
| 41 | } |
||
| 42 | |||
| 43 | $io = new SymfonyStyle($input, $output); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var AuditManager |
||
| 47 | */ |
||
| 48 | $manager = $this->container->get('dh_doctrine_audit.manager'); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var UpdateHelper |
||
| 52 | */ |
||
| 53 | $updater = new UpdateHelper($manager); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var RegistryInterface |
||
| 57 | */ |
||
| 58 | $registry = $this->container->get('doctrine'); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var Connection |
||
| 62 | */ |
||
| 63 | $connection = $registry->getManager()->getConnection(); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var AbstractSchemaManager |
||
| 67 | */ |
||
| 68 | $schemaManager = $connection->getSchemaManager(); |
||
| 69 | $tables = $schemaManager->listTables(); |
||
| 70 | $audits = []; |
||
| 71 | |||
| 72 | $regex = sprintf( |
||
| 73 | '#^%s(.*)%s$#', |
||
| 74 | preg_quote($updater->getConfiguration()->getTablePrefix(), '#'), |
||
| 75 | preg_quote($updater->getConfiguration()->getTableSuffix(), '#') |
||
| 76 | ); |
||
| 77 | |||
| 78 | foreach ($tables as $table) { |
||
| 79 | if (preg_match($regex, $table->getName())) { |
||
| 80 | $audits[] = $table; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $progressBar = new ProgressBar($output, \count($audits)); |
||
| 85 | $progressBar->setBarWidth(70); |
||
| 86 | $progressBar->setFormat("%message%\n".$progressBar->getFormatDefinition('debug')); |
||
| 87 | |||
| 88 | $progressBar->setMessage('Starting...'); |
||
| 89 | $progressBar->start(); |
||
| 90 | |||
| 91 | foreach ($audits as $table) { |
||
| 92 | $progressBar->setMessage("Processing audit tables... (<info>{$table->getName()}</info>)"); |
||
| 93 | $progressBar->display(); |
||
| 94 | |||
| 95 | $operations = $updater->checkAuditTable($schemaManager, $table); |
||
| 96 | if (isset($operations['add']) || isset($operations['update']) || isset($operations['remove'])) { |
||
| 97 | $updater->updateAuditTable($schemaManager, $table, $operations, $registry->getManager()); |
||
| 98 | } |
||
| 99 | |||
| 100 | $progressBar->advance(); |
||
| 101 | } |
||
| 102 | |||
| 103 | $progressBar->setMessage('Processing audit tables... (<info>done</info>)'); |
||
| 104 | $progressBar->display(); |
||
| 105 | |||
| 106 | $io->newLine(2); |
||
| 107 | |||
| 108 | $io->success('Success.'); |
||
| 109 | |||
| 110 | // if not released explicitly, Symfony releases the lock |
||
| 111 | // automatically when the execution of the command ends |
||
| 112 | $this->release(); |
||
| 113 | |||
| 114 | return 0; |
||
| 115 | } |
||
| 127 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.