InstanceList   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 14
eloc 46
c 1
b 0
f 1
dl 0
loc 94
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A listDatabasesVersion() 0 8 1
A listInstances() 0 11 2
B writeResult() 0 24 7
A execute() 0 19 3
A configure() 0 5 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Command;
4
5
use Db3v4l\Core\DatabaseSchemaManager;
0 ignored issues
show
Bug introduced by
The type Db3v4l\Core\DatabaseSchemaManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Yaml\Yaml;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Yaml\Yaml was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class InstanceList extends SQLExecutingCommand
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class InstanceList
Loading history...
12
{
13
    protected static $defaultName = 'db3v4l:instance:list';
14
15
    protected function configure()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function configure()
Loading history...
16
    {
17
        $this
18
            ->setDescription('Lists all configured database servers')
19
            ->addCommonOptions()
0 ignored issues
show
Coding Style introduced by
Space after closing parenthesis of function call prohibited
Loading history...
20
        ;
21
    }
22
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
     * @todo allow to dump full configuration, not just db vendor + version
0 ignored issues
show
Coding Style introduced by
Tag @todo cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value for @todo tag indented incorrectly; expected 3 spaces but found 1
Loading history...
25
     * @param InputInterface $input
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
26
     * @param OutputInterface $output
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
27
     * @return int
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
28
     * @throws \Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $this->setOutput($output);
33
        $this->setVerbosity($output->getVerbosity());
34
35
        $instanceList = $this->parseCommonOptions($input);
36
37
        $result = $this->listInstances($instanceList);
38
39
        $extraResults = $this->listDatabasesVersion($instanceList)['data'];
40
        foreach($result as $instanceName => $instanceDesc) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
41
            if (isset($extraResults[$instanceName])) {
42
                $result[$instanceName]['version'] = $extraResults[$instanceName];
43
            }
44
        }
45
46
        $this->writeResult($result);
47
48
        return 0;
49
    }
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @todo allow to retrieve exact version number dynamically, see getRetrieveVersionInfoSqlAction
0 ignored issues
show
Coding Style introduced by
Tag @todo cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value for @todo tag indented incorrectly; expected 3 spaces but found 1
Loading history...
53
     * @param string[][] $instanceList
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
54
     * @return string[][]
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
55
     */
56
    protected function listInstances($instanceList)
57
    {
58
        $out = [];
59
        foreach($instanceList as $instanceName => $connectionSpec) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
60
            //$connectionSpec = $this->dbConfigurationManager->getInstanceConfiguration($instanceName);
61
            $out[$instanceName] = [
62
                'vendor' => $connectionSpec['vendor'],
63
                'version' => $connectionSpec['version']
64
            ];
65
        }
66
        return $out;
67
    }
68
69
    protected function listDatabasesVersion($instanceList)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function listDatabasesVersion()
Loading history...
70
    {
71
        return $this->executeSqlAction(
72
            $instanceList,
73
            'Getting database version information',
74
            function ($schemaManager, $instanceName) {
0 ignored issues
show
Unused Code introduced by
The parameter $instanceName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

74
            function ($schemaManager, /** @scrutinizer ignore-unused */ $instanceName) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
                /** @var DatabaseSchemaManager $schemaManager */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
76
                return $schemaManager->getRetrieveVersionInfoSqlAction();
77
            }
78
        );
79
    }
80
81
    protected function writeResult($result)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function writeResult()
Loading history...
82
    {
83
        switch ($this->outputFormat) {
84
            case 'json':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
85
                $data = json_encode($result, JSON_PRETTY_PRINT);
86
                break;
87
            case 'php':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
88
                $data = var_export($result, true);
89
                break;
90
            case 'text':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
91
            case 'yml':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
92
            case 'yaml':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
93
                $data = Yaml::dump($result);
94
                break;
95
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
96
                throw new \Exception("Unsupported output format: '{$this->outputFormat}'");
97
                break;
98
        }
99
100
        if ($this->outputFile != null) {
101
            file_put_contents($this->outputFile, $data);
102
            $this->writeln("Results saved to file {$this->outputFile}");
103
        } else {
104
            $this->writeln($data, OutputInterface::VERBOSITY_QUIET,  OutputInterface::OUTPUT_RAW);
105
        }
106
107
    }
108
}
109