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.

FindSitesCommand::execute()   C
last analyzed

Complexity

Conditions 11
Paths 54

Size

Total Lines 46
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 33
nc 54
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 File_Iterator_Factory;
6
use Selim\Util;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Question\Question;
12
13
class FindSitesCommand extends SelimCommand{
14
    protected function configure()
15
    {
16
        parent::configure();
17
        $this
18
            ->setName('find')
19
            ->setDescription('Find silverstripe sites on your hdd')
20
            ->addArgument(
21
                'path',
22
                InputArgument::REQUIRED,
23
                'Path where the script should start searching recursively'
24
            )->addOption(
25
                'skip-known-paths',
26
                's',
27
                InputOption::VALUE_NONE,
28
                'Skip all paths which are already in your selim config'
29
            );
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $cfg = $this->getSelimConfig($input);
35
        $skippaths = $input->getOption("skip-known-paths") ? true : false;
36
        $path = realpath($input->getArgument("path"));
37
        $projects = array();
38
        $question_helper =  $this->getHelper("question");
39
40
        $output->write("Start searching _config.php files...");
41
        $fact = new File_Iterator_Factory();
42
        $iterator = $fact->getFileIterator($path,"php","_config");
43
        $output->writeln("OK");
44
45
        $output->write("Filter for project paths...");
46
        while($file = $iterator->current()){
47
            $content = Util::stripPhpComments(file_get_contents($file));
48
            if(preg_match("/\\\$project\\s=/",$content)){
49
                array_push($projects,dirname($file));
50
            }
51
            $iterator->next();
52
        }
53
        $output->writeln("OK");
54
55
        if(count($projects)){
56
            $sites_added = false;
57
            $output->writeln("found ".count($projects)." possible sites");
58
            foreach($projects as $p){
59
                if($skippaths && $cfg->sitePathExists($p)) continue;
60
61
                $question = new Question("Please enter name for '$p' (leave empty to skip)");
62
                do {
63
                    $name = $question_helper->ask($input, $output, $question);
64
                }while($cfg->siteExists($name));
65
66
                if($name){
67
                    $sites_added = true;
68
                    $cfg->addSite($name,$p);
69
                }
70
            }
71
            if($sites_added) {
72
                $output->write("Writing config.json ...");
73
                $cfg->write();
74
                $output->writeln("OK");
75
            }
76
        }
77
    }
78
}