| Conditions | 12 |
| Paths | 84 |
| Total Lines | 81 |
| Code Lines | 47 |
| 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 |
||
| 109 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 110 | { |
||
| 111 | //Every available database |
||
| 112 | $databases = $this->config->getDatabases(); |
||
| 113 | |||
| 114 | if ($input->getArgument('db')) { |
||
| 115 | $databases = [$input->getArgument('db')]; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (empty($databases)) { |
||
| 119 | $this->io->error('No databases found.'); |
||
| 120 | |||
| 121 | return 1; |
||
| 122 | } |
||
| 123 | |||
| 124 | $grid = $this->table->setHeaders([ |
||
| 125 | 'Name (ID):', |
||
| 126 | 'Database:', |
||
| 127 | 'Driver:', |
||
| 128 | 'Prefix:', |
||
| 129 | 'Status:', |
||
| 130 | 'Tables:', |
||
| 131 | 'Count Records:', |
||
| 132 | ]); |
||
| 133 | |||
| 134 | foreach ($databases as $database) { |
||
| 135 | if ($database instanceof DatabasePartial) { |
||
| 136 | $database = $database->getName(); |
||
| 137 | } |
||
| 138 | |||
| 139 | $database = $this->factory->database($database); |
||
| 140 | $driver = $database->getDriver(); |
||
| 141 | |||
| 142 | $source = $driver->getSource(); |
||
| 143 | |||
| 144 | if (\is_file($driver->getSource())) { |
||
| 145 | $source = \basename($driver->getSource()); |
||
| 146 | } |
||
| 147 | |||
| 148 | $header = [ |
||
| 149 | $database->getName(), $source, |
||
| 150 | $driver->getType(), |
||
| 151 | $database->getPrefix() ?: self::SKIP, |
||
| 152 | ]; |
||
| 153 | |||
| 154 | try { |
||
| 155 | $driver->connect(); |
||
| 156 | } catch (Exception $exception) { |
||
| 157 | $grid->addRow(\array_merge($header, [ |
||
| 158 | "<fg=red>{$exception->getMessage()}</fg=red>", |
||
| 159 | self::SKIP, |
||
| 160 | self::SKIP, |
||
| 161 | ])); |
||
| 162 | |||
| 163 | if ($database->getName() !== \end($databases)) { |
||
| 164 | $grid->addRow(new TableSeparator()); |
||
| 165 | } |
||
| 166 | |||
| 167 | continue; |
||
| 168 | } |
||
| 169 | |||
| 170 | $header[] = '<info>connected</info>'; |
||
| 171 | |||
| 172 | foreach ($database->getTables() as $table) { |
||
| 173 | $grid->addRow(\array_merge( |
||
| 174 | $header, |
||
| 175 | [$table->getName(), \number_format($table->count())] |
||
| 176 | )); |
||
| 177 | $header = ['', '', '', '', '']; |
||
| 178 | } |
||
| 179 | |||
| 180 | $header[1] && $grid->addRow(\array_merge($header, ['no tables', 'no records'])); |
||
| 181 | |||
| 182 | if ($database->getName() !== \end($databases)) { |
||
| 183 | $grid->addRow(new TableSeparator()); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $grid->render(); |
||
| 188 | |||
| 189 | return 0; |
||
| 190 | } |
||
| 192 |