MigrateCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 20
loc 20
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 11 11 2
A configure() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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
}