Total Complexity | 54 |
Total Lines | 397 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like CoverageThresholdTask often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CoverageThresholdTask, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | class CoverageThresholdTask extends Task |
||
40 | { |
||
41 | use ClasspathAware; |
||
42 | |||
43 | /** |
||
44 | * Holds the exclusions |
||
45 | * |
||
46 | * @var Excludes |
||
47 | */ |
||
48 | private $excludes = null; |
||
49 | |||
50 | /** |
||
51 | * Holds an optional database file |
||
52 | * |
||
53 | * @var File |
||
54 | */ |
||
55 | private $database = null; |
||
56 | |||
57 | /** |
||
58 | * Holds the coverage threshold for the entire project |
||
59 | * |
||
60 | * @var integer |
||
61 | */ |
||
62 | private $perProject = 25; |
||
63 | |||
64 | /** |
||
65 | * Holds the coverage threshold for any class |
||
66 | * |
||
67 | * @var integer |
||
68 | */ |
||
69 | private $perClass = 25; |
||
70 | |||
71 | /** |
||
72 | * Holds the coverage threshold for any method |
||
73 | * |
||
74 | * @var integer |
||
75 | */ |
||
76 | private $perMethod = 25; |
||
77 | |||
78 | /** |
||
79 | * Holds the minimum found coverage value for a class |
||
80 | * |
||
81 | * @var integer |
||
82 | */ |
||
83 | private $minClassCoverageFound = null; |
||
84 | |||
85 | /** |
||
86 | * Holds the minimum found coverage value for a method |
||
87 | * |
||
88 | * @var integer |
||
89 | */ |
||
90 | private $minMethodCoverageFound = null; |
||
91 | |||
92 | /** |
||
93 | * Number of statements in the entire project |
||
94 | * |
||
95 | * @var integer |
||
96 | */ |
||
97 | private $projectStatementCount = 0; |
||
98 | |||
99 | /** |
||
100 | * Number of covered statements in the entire project |
||
101 | * |
||
102 | * @var integer |
||
103 | */ |
||
104 | private $projectStatementsCovered = 0; |
||
105 | |||
106 | /** |
||
107 | * Whether to enable detailed logging |
||
108 | * |
||
109 | * @var boolean |
||
110 | */ |
||
111 | private $verbose = false; |
||
112 | |||
113 | /** |
||
114 | * Sets the optional coverage database to use |
||
115 | * |
||
116 | * @param File The database file |
||
|
|||
117 | */ |
||
118 | public function setDatabase(File $database) |
||
119 | { |
||
120 | $this->database = $database; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Sets the coverage threshold for entire project |
||
125 | * |
||
126 | * @param integer $threshold Coverage threshold for entire project |
||
127 | */ |
||
128 | public function setPerProject($threshold) |
||
129 | { |
||
130 | $this->perProject = $threshold; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Sets the coverage threshold for any class |
||
135 | * |
||
136 | * @param integer $threshold Coverage threshold for any class |
||
137 | */ |
||
138 | public function setPerClass($threshold) |
||
139 | { |
||
140 | $this->perClass = $threshold; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Sets the coverage threshold for any method |
||
145 | * |
||
146 | * @param integer $threshold Coverage threshold for any method |
||
147 | */ |
||
148 | public function setPerMethod($threshold) |
||
149 | { |
||
150 | $this->perMethod = $threshold; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Sets whether to enable detailed logging or not |
||
155 | * |
||
156 | * @param boolean $verbose |
||
157 | */ |
||
158 | public function setVerbose($verbose) |
||
159 | { |
||
160 | $this->verbose = StringHelper::booleanValue($verbose); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Filter covered statements |
||
165 | * |
||
166 | * @param integer $var Coverage CODE/count |
||
167 | * @return boolean |
||
168 | */ |
||
169 | protected function filterCovered($var) |
||
170 | { |
||
171 | return ($var >= 0 || $var === -2); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Create excludes object |
||
176 | * |
||
177 | * @return Excludes |
||
178 | */ |
||
179 | public function createExcludes() |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Calculates the coverage threshold |
||
188 | * |
||
189 | * @param string $filename The filename to analyse |
||
190 | * @param array $coverageInformation Array with coverage information |
||
191 | * @throws BuildException |
||
192 | */ |
||
193 | protected function calculateCoverageThreshold($filename, $coverageInformation) |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | |||
372 | public function main() |
||
439 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths