Conditions | 11 |
Paths | 54 |
Total Lines | 46 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |