Conditions | 20 |
Paths | 2 |
Total Lines | 98 |
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 |
||
35 | * @author Henrik Bjornskov |
||
36 | */ |
||
37 | class CodeCoverageExtension implements Extension |
||
38 | { |
||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function load(ServiceContainer $container, array $params = []): void |
||
43 | { |
||
44 | foreach ($container->getByTag('console.commands') as $command) { |
||
45 | $command->addOption('no-coverage', null, InputOption::VALUE_NONE, 'Skip code coverage generation'); |
||
46 | } |
||
47 | |||
48 | $container->define('code_coverage.filter', static function () { |
||
49 | return new Filter(); |
||
50 | }); |
||
51 | |||
52 | $container->define('code_coverage', static function ($container) { |
||
53 | try { |
||
54 | $coverage = new CodeCoverage(null, $container->get('code_coverage.filter')); |
||
55 | } catch (RuntimeException $error) { |
||
56 | throw new NoCoverageDriverAvailableException( |
||
57 | 'There is no available coverage driver to be used.', |
||
58 | 0, |
||
59 | $error |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | return $coverage; |
||
64 | }); |
||
65 | |||
66 | $container->define('code_coverage.options', static function ($container) use ($params) { |
||
67 | $options = !empty($params) ? $params : $container->getParam('code_coverage'); |
||
68 | |||
69 | if (!isset($options['format'])) { |
||
70 | $options['format'] = ['html']; |
||
71 | } elseif (!is_array($options['format'])) { |
||
72 | $options['format'] = (array) $options['format']; |
||
73 | } |
||
74 | |||
75 | if (isset($options['output'])) { |
||
76 | if (!is_array($options['output']) && 1 === count($options['format'])) { |
||
77 | $format = $options['format'][0]; |
||
78 | $options['output'] = [$format => $options['output']]; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if (!isset($options['show_uncovered_files'])) { |
||
83 | $options['show_uncovered_files'] = true; |
||
84 | } |
||
85 | |||
86 | if (!isset($options['lower_upper_bound'])) { |
||
87 | $options['lower_upper_bound'] = 35; |
||
88 | } |
||
89 | |||
90 | if (!isset($options['high_lower_bound'])) { |
||
91 | $options['high_lower_bound'] = 70; |
||
92 | } |
||
93 | |||
94 | return $options; |
||
95 | }); |
||
96 | |||
97 | $container->define('code_coverage.reports', static function ($container) { |
||
98 | $options = $container->get('code_coverage.options'); |
||
99 | |||
100 | $reports = []; |
||
101 | |||
102 | foreach ($options['format'] as $format) { |
||
103 | switch ($format) { |
||
104 | case 'clover': |
||
105 | $reports['clover'] = new Report\Clover(); |
||
106 | |||
107 | break; |
||
108 | case 'php': |
||
109 | $reports['php'] = new Report\PHP(); |
||
110 | |||
111 | break; |
||
112 | case 'text': |
||
113 | $reports['text'] = new Report\Text( |
||
114 | $options['lower_upper_bound'], |
||
115 | $options['high_lower_bound'], |
||
116 | $options['show_uncovered_files'], |
||
117 | /* $showOnlySummary */ |
||
118 | false |
||
119 | ); |
||
120 | |||
121 | break; |
||
122 | case 'xml': |
||
123 | $reports['xml'] = new Report\Xml\Facade(Version::id()); |
||
124 | |||
125 | break; |
||
126 | case 'crap4j': |
||
127 | $reports['crap4j'] = new Report\Crap4j(); |
||
128 | |||
129 | break; |
||
130 | case 'html': |
||
131 | $reports['html'] = new Report\Html\Facade(); |
||
132 | |||
133 | break; |
||
165 |