GenerateRelationModel::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 29
Ratio 100 %

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of Pomm's Cli package.
4
 *
5
 * (c) 2014 - 2019 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 - 2019 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
            ->addOption(
58
                'path-pattern',
59
                null,
60
                InputOption::VALUE_REQUIRED,
61
                'Use a different directory pattern when generating classes.',
62
                '{session}/{schema}Schema'
63
            )
64
        ;
65
    }
66
67
    /**
68
     * execute
69
     *
70
     * @see Command
71
     */
72
    protected function execute(InputInterface $input, OutputInterface $output)
73
    {
74
        parent::execute($input, $output);
75
76
        $session = $this->mustBeModelManagerSession($this->getSession());
77
78
        $this->pathFile  = $this->getPathFile(
79
            $input->getArgument('config-name'),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('config-name') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, PommProject\Cli\Command\...eCommand::getPathFile() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
80
            $this->relation,
0 ignored issues
show
Bug introduced by
It seems like $this->relation can also be of type array<integer,string> or null; however, PommProject\Cli\Command\...eCommand::getPathFile() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
81
            'Model',
82
            '',
83
            $input->getOption('psr4'),
84
            $input->getOption('path-pattern')
85
        );
86
        $this->namespace = $this->getNamespace($input->getArgument('config-name'), null, $input->getOption('path-pattern'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('config-name') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, PommProject\Cli\Command\...Command::getNamespace() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
87
88
        $this->updateOutput(
89
            $output,
90
            (new ModelGenerator(
91
                $session,
92
                $this->schema,
0 ignored issues
show
Bug introduced by
It seems like $this->schema can also be of type array<integer,string> or null; however, PommProject\ModelManager...enerator::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
93
                $this->relation,
0 ignored issues
show
Bug introduced by
It seems like $this->relation can also be of type array<integer,string> or null; however, PommProject\ModelManager...enerator::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
94
                $this->pathFile,
95
                $this->namespace
96
            ))->generate(new ParameterHolder(['force' => $input->getOption('force')]))
97
        );
98
99
        return 0;
100
    }
101
}
102