Conditions | 10 |
Paths | 156 |
Total Lines | 52 |
Code Lines | 32 |
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 |
||
86 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
87 | { |
||
88 | $formatter = $input->getOption('format') == 'json' |
||
89 | ? new JsonFormatter($output) |
||
90 | : new DefaultFormatter($output); |
||
91 | |||
92 | $formatter->onInvokationStart(); |
||
93 | |||
94 | $engineBuilder = new EngineBuilder; |
||
95 | |||
96 | if ($filter = $input->getOption('filter')) { |
||
97 | $engineBuilder->setFilter(new RegexpFilter($filter)); |
||
98 | } elseif ($input->getOption('flagged-only')) { |
||
99 | $engineBuilder->setFilter(new UnnamedFilter); |
||
100 | } |
||
101 | |||
102 | if ($bootstrap = $this->readBootstrap($input)) { |
||
103 | $formatter->onBootstrap($bootstrap); |
||
104 | } |
||
105 | |||
106 | switch ($input->getOption('runner')) { |
||
107 | case 'process': |
||
108 | $engineBuilder->setRunner(new ProcessRunner($bootstrap)); |
||
109 | break; |
||
110 | case 'eval': |
||
111 | $engineBuilder->setRunner(new EvalRunner($bootstrap)); |
||
112 | break; |
||
113 | default: |
||
114 | throw new \RuntimeException("Unknown runner '{$input->getOption('runner')}'"); |
||
115 | } |
||
116 | |||
117 | if ($input->getOption('ignore-unknown-annotations')) { |
||
118 | $engineBuilder->setIgnoreUnknownAnnotations(); |
||
119 | } |
||
120 | |||
121 | $engine = $engineBuilder->buildEngine(); |
||
122 | |||
123 | $engine->registerListener($formatter); |
||
124 | |||
125 | $exitStatus = new ExitStatusListener; |
||
126 | $engine->registerListener($exitStatus); |
||
127 | |||
128 | foreach ($input->getArgument('source') as $source) { |
||
129 | foreach (new SourceFileIterator($source) as $filename => $contents) { |
||
130 | $formatter->onFile($filename); |
||
131 | $engine->testFile($contents); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | $formatter->onInvokationEnd(); |
||
136 | |||
137 | return $exitStatus->getStatusCode(); |
||
138 | } |
||
157 |