Conditions | 10 |
Paths | 13 |
Total Lines | 35 |
Code Lines | 24 |
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 |
||
69 | protected function execute(InputInterface $input, OutputInterface $output) |
||
70 | { |
||
71 | $dir = $input->getOption('debug-dir'); |
||
72 | if (!is_dir($dir)) { |
||
73 | throw new Exception("Debug dir $dir doesn't exist"); |
||
74 | } |
||
75 | $files = glob($dir . '/*'); |
||
76 | if ($input->getOption('list')) { |
||
77 | foreach ($files as $file) { |
||
78 | $output->writeln(basename($file)); |
||
79 | } |
||
80 | return; |
||
81 | } |
||
82 | if ($entry = $input->getArgument('entry')) { |
||
83 | if ($entry[0] === '^') { |
||
84 | $back = ((int) substr($entry, 1)) + 1; |
||
85 | while ($back--) { |
||
86 | $show = array_pop($files); |
||
87 | } |
||
88 | } else { |
||
89 | foreach ($files as $file) { |
||
90 | if (basename($file) === $entry) { |
||
91 | $show = $file; |
||
92 | break; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | } else { |
||
97 | $show = array_pop($files); |
||
98 | } |
||
99 | if (!isset($show)) { |
||
100 | throw new Exception("Couldn't find suitable entry"); |
||
101 | } |
||
102 | $output->write(file_get_contents($show), false, OutputInterface::OUTPUT_RAW); |
||
103 | } |
||
104 | } |
||
107 |