GenerateRelationStructure   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 2
cbo 4
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 26 1
A execute() 0 29 1
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\StructureGenerator;
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
 * GenerateRelationStructure
21
 *
22
 * Command to scan a relation and (re)build the according structure file.
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       Command
29
 */
30
class GenerateRelationStructure extends RelationAwareCommand
31
{
32
    /**
33
     * configure
34
     *
35
     * @see Command
36
     */
37
    protected function configure()
38
    {
39
        $this
40
            ->setName('pomm:generate:structure')
41
            ->setDescription('Generate a RowStructure file based on table schema.')
42
            ->setHelp(<<<HELP
43
HELP
44
        )
45
            ;
46
        parent::configure();
47
        $this
48
            ->addOption(
49
                'psr4',
50
                null,
51
                InputOption::VALUE_NONE,
52
                'Use PSR4 structure.'
53
            )
54
            ->addOption(
55
                'path-pattern',
56
                null,
57
                InputOption::VALUE_REQUIRED,
58
                'Use a different directory pattern when generating classes.',
59
                '{session}/{schema}Schema'
60
            )
61
        ;
62
    }
63
64
    /**
65
     * execute
66
     *
67
     * @see Command
68
     */
69
    protected function execute(InputInterface $input, OutputInterface $output)
70
    {
71
        parent::execute($input, $output);
72
73
        $session = $this->mustBeModelManagerSession($this->getSession());
74
75
        $this->pathFile = $this->getPathFile(
76
            $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...
77
            $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...
78
            null,
79
            'AutoStructure',
80
            $input->getOption('psr4'),
81
            $input->getOption('path-pattern')
82
        );
83
        $this->namespace = $this->getNamespace($input->getArgument('config-name'), 'AutoStructure', $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...
84
85
        $this->updateOutput(
86
            $output,
87
            (new StructureGenerator(
88
                $session,
89
                $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...
90
                $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...
91
                $this->pathFile,
92
                $this->namespace
93
            ))->generate(new ParameterHolder())
94
        );
95
96
        return 0;
97
    }
98
}
99