1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | namespace Cart\Commands; |
||
4 | |||
5 | use Symfony\Component\Console\Command\Command; |
||
6 | use Symfony\Component\Console\Input\InputInterface; |
||
7 | use Symfony\Component\Console\Output\OutputInterface; |
||
8 | use Symfony\Component\Finder\Finder; |
||
9 | |||
10 | View Code Duplication | class MigrateRollbackCommand extends Command |
|
0 ignored issues
–
show
|
|||
11 | { |
||
12 | protected function configure() |
||
13 | { |
||
14 | $this |
||
15 | ->setName('cart:migrate:rollback') |
||
16 | ->setDescription('Deletes tables cart.'); |
||
17 | } |
||
18 | |||
19 | |||
20 | protected function execute(InputInterface $input, OutputInterface $output) |
||
21 | { |
||
22 | foreach (Finder::create()->files()->name('*.php') |
||
23 | ->in(__DIR__. '/../../migrations') as $file) { |
||
24 | $classes = get_declared_classes(); |
||
25 | include $file->getRealPath(); |
||
26 | $diff = array_diff(get_declared_classes(), $classes); |
||
27 | $class = reset($diff); |
||
28 | (new $class())->down(); |
||
29 | $output->writeln('<fg=green>Success rollback migration: ' . basename($file->getFilename(), '.php') .'</>'); |
||
30 | } |
||
31 | } |
||
32 | } |
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.