Completed
Push — master ( 5f27ef...d1e65c )
by grégoire
12:16 queued 07:49
created

GenerateRelationModel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 10
Bugs 2 Features 2
Metric Value
wmc 2
c 10
b 2
f 2
lcom 1
cbo 5
dl 56
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 22 22 1
A execute() 20 20 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
/*
3
 * This file is part of Pomm's Cli package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Cli\Command;
11
12
use PommProject\Foundation\ParameterHolder;
13
use PommProject\ModelManager\Generator\ModelGenerator;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * GenerateRelationModel
21
 *
22
 * Model generation command.
23
 *
24
 * @package   Cli
25
 * @copyright 2014 - 2015 Grégoire HUBERT
26
 * @author    Grégoire HUBERT
27
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
28
 * @see       PommAwareCommand
29
 */
30 View Code Duplication
class GenerateRelationModel extends RelationAwareCommand
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...
31
{
32
    /**
33
     * configure
34
     *
35
     * @see Command
36
     */
37
    public function configure()
38
    {
39
        $this
40
            ->setName('pomm:generate:model')
41
            ->setDescription('Generate a new model file.')
42
            ;
43
        parent::configure();
44
        $this
45
            ->addOption(
46
                'force',
47
                null,
48
                InputOption::VALUE_NONE,
49
                'Force overwriting an existing file.'
50
            )
51
            ->addOption(
52
                'psr4',
53
                null,
54
                InputOption::VALUE_NONE,
55
                'Use PSR4 structure.'
56
            )
57
        ;
58
    }
59
60
    /**
61
     * execute
62
     *
63
     * @see Command
64
     */
65
    protected function execute(InputInterface $input, OutputInterface $output)
66
    {
67
        parent::execute($input, $output);
68
69
        $session = $this->mustBeModelManagerSession($this->getSession());
70
71
        $this->pathFile  = $this->getPathFile($input->getArgument('config-name'), $this->relation, 'Model', '', $input->getOption('psr4'));
72
        $this->namespace = $this->getNamespace($input->getArgument('config-name'));
73
74
        $this->updateOutput(
75
            $output,
76
            (new ModelGenerator(
77
                $session,
78
                $this->schema,
79
                $this->relation,
80
                $this->pathFile,
81
                $this->namespace
82
            ))->generate(new ParameterHolder(['force' => $input->getOption('force')]))
83
        );
84
    }
85
}
86