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   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
C execute() 0 46 11
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
}