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