AbstractCommand::getSchemaPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the "RocketORM" package.
5
 *
6
 * https://github.com/RocketORM/ORM
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Rocket\ORM\Console\Command;
13
14
use Rocket\ORM\Connection\ConnectionInterface;
15
use \Rocket\ORM\Config\ConfigLoader;
16
use Rocket\ORM\Generator\Schema\Loader\SchemaLoader;
17
use Rocket\ORM\Rocket;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * @author Sylvain Lorinet <[email protected]>
24
 */
25
class AbstractCommand extends Command
26
{
27
    /**
28
     * @param InputInterface  $input
29
     * @param OutputInterface $output
30
     */
31
    protected function initialize(InputInterface $input, OutputInterface $output)
32
    {
33
        $configLoader = new ConfigLoader($input->getOption('rocket-config'));
34
        Rocket::setConfiguration($configLoader->all());
35
    }
36
37
    /**
38
     * @param InputInterface|null $input
39
     * @param string|null         $name
40
     *
41
     * @return ConnectionInterface
42
     */
43
    protected function getConnection(InputInterface $input = null, $name = null)
44
    {
45
        if (null == $name) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
46
            if (null != $input) {
47
                $name = $input->getOption('connection', 'default');
0 ignored issues
show
Unused Code introduced by
The call to InputInterface::getOption() has too many arguments starting with 'default'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
48
            }
49
            else {
50
                $name = 'default';
51
            }
52
        }
53
54
        return Rocket::getConnection($name);
55
    }
56
57
    /**
58
     * @param string|array $path
59
     * @param string|array $exclude
60
     *
61
     * @return array
62
     */
63
    protected function getSchemas($path, $exclude = [])
64
    {
65
        $schemaLoader = new SchemaLoader($path, $exclude, Rocket::getConfiguration('generator.loader'));
0 ignored issues
show
Bug introduced by
It seems like $exclude defined by parameter $exclude on line 63 can also be of type string; however, Rocket\ORM\Generator\Sch...maLoader::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
Unused Code introduced by
The call to SchemaLoader::__construct() has too many arguments starting with \Rocket\ORM\Rocket::getC...ion('generator.loader').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
66
67
        return $schemaLoader->load();
68
    }
69
70
    /**
71
     * @param OutputInterface $output
72
     * @param string          $message
73
     * @param bool            $newLine
74
     * @param int             $verbosity
75
     */
76
    private function write(OutputInterface $output, $message, $newLine = true, $verbosity = OutputInterface::VERBOSITY_VERBOSE)
77
    {
78
        if ($verbosity <= $output->getVerbosity()) {
79
            $output->write($message);
80
            if ($newLine) {
81
                $output->writeln('');
82
            }
83
        }
84
    }
85
86
    /**
87
     * @param OutputInterface $output
88
     * @param string          $message
89
     * @param bool            $newLine
90
     */
91
    protected function debug(OutputInterface $output, $message, $newLine = true)
92
    {
93
        $this->write($output, $message, $newLine, OutputInterface::VERBOSITY_DEBUG);
94
    }
95
96
    /**
97
     * @param OutputInterface $output
98
     * @param string          $message
99
     * @param bool            $newLine
100
     */
101
    protected function verbose(OutputInterface $output, $message, $newLine = true)
102
    {
103
        $this->write($output, $message, $newLine, OutputInterface::VERBOSITY_VERBOSE);
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    protected function getSchemaPath()
110
    {
111
        return __DIR__ . '/../../../../../fixtures/schemas';
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    protected function getSqlOutputPath()
118
    {
119
        return __DIR__ . '/../../../../../fixtures/sql';
120
    }
121
}
122