GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DefaultCommand::execute()   F
last analyzed

Complexity

Conditions 10
Paths 384

Size

Total Lines 49
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 3.7894
c 0
b 0
f 0
cc 10
eloc 30
nc 384
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Selim\Commands;
4
5
use Selim\ConsoleOutput;
6
use Selim\ConsoleOutputTable;
7
use Selim\SilverstripePage;
8
use Selim\SiteConfig;
9
use Selim\Util;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class DefaultCommand extends SelimCommand{
15
    protected function configure()
16
    {
17
        parent::configure();
18
        $this
19
            ->setName('start')
20
            ->setDescription('Analyze all sites added.')
21
            ->addOption(
22
                'filter-name',
23
                null,
24
                InputOption::VALUE_REQUIRED,
25
                'regex, filter sites by name'
26
            )->addOption(
27
                'filter-version',
28
                null,
29
                InputOption::VALUE_REQUIRED,
30
                'regex, filter sites by version'
31
            )->addOption(
32
                'filter-module',
33
                null,
34
                InputOption::VALUE_REQUIRED,
35
                'regex, filter sites by installed modules'
36
            )->addOption(
37
                'format',
38
                null,
39
                InputOption::VALUE_REQUIRED,
40
                'Define a output format.'
41
            )->addOption(
42
                'table',
43
                null,
44
                InputOption::VALUE_NONE,
45
                'Print all sites as a table'
46
            )->addOption(
47
                'filter-da',
48
                null,
49
                InputOption::VALUE_NONE,
50
                'regex, filter sites where Security::setDefaultAdmin() is used in config.php'
51
            )->addOption(
52
                'filter-env',
53
                null,
54
                InputOption::VALUE_REQUIRED,
55
                'regex, filter sites by environment type'
56
            );
57
    }
58
59
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61
        $cfg = $this->getSelimConfig($input);
62
        $sites = $cfg->getSites();
63
64
        $filter_name = $input->getOption("filter-name");
65
        if (strlen($filter_name)) {
66
            $sites = Util::filterSitesByName($sites, $filter_name);
67
        }
68
69
        $sspages = array();
70
        foreach ($sites as $sc) {
71
            if ($sc instanceof SiteConfig) {
72
                array_push($sspages, new SilverstripePage($sc));
73
            }
74
        }
75
76
        $filter_version = $input->getOption("filter-version");
77
        if (strlen($filter_version)) {
78
            $sspages = Util::filterPagesByVersion($sspages, $filter_version);
79
        }
80
81
        $filter_module = $input->getOption("filter-module");
82
        if (strlen($filter_module)) {
83
            $sspages = Util::filterPagesByModules($sspages, $filter_module);
84
        }
85
86
        if ($input->getOption("filter-da")) {
87
            $sspages = Util::filterPagesByDefaultAdmin($sspages, true);
88
        }
89
90
        $filter_env = $input->getOption("filter-env");
91
        if ($input->getOption("filter-env")) {
92
            $sspages = Util::filterPagesByEnvironmentType($sspages, $filter_env);
93
        }
94
95
        if ($input->getOption("table")) {
96
            $out = new ConsoleOutputTable($sspages);
97
        } else {
98
            $out = new ConsoleOutput($sspages);
99
        }
100
101
        $format = $input->getOption("format");
102
        if (strlen($format)) {
103
            $out->write($format);
104
        } else {
105
            $out->write();
106
        }
107
    }
108
}