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