Conditions | 10 |
Paths | 29 |
Total Lines | 66 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
80 | private function getLinesToBeCoveredOrUsed(string $className, string $methodName, string $mode): array |
||
81 | { |
||
82 | $annotations = $this->parseTestMethodAnnotations( |
||
83 | $className, |
||
84 | $methodName |
||
85 | ); |
||
86 | |||
87 | $classShortcut = null; |
||
88 | |||
89 | if (!empty($annotations['class'][$mode . 'DefaultClass'])) { |
||
90 | if (count($annotations['class'][$mode . 'DefaultClass']) > 1) { |
||
91 | throw new CodeCoverageException( |
||
92 | sprintf( |
||
93 | 'More than one @%sClass annotation in class or interface "%s".', |
||
94 | $mode, |
||
95 | $className |
||
96 | ) |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | $classShortcut = $annotations['class'][$mode . 'DefaultClass'][0]; |
||
101 | } |
||
102 | |||
103 | $list = $annotations['class'][$mode] ?? []; |
||
104 | |||
105 | if (isset($annotations['method'][$mode])) { |
||
106 | $list = array_merge($list, $annotations['method'][$mode]); |
||
107 | } |
||
108 | |||
109 | $codeUnits = CodeUnitCollection::fromArray([]); |
||
110 | $mapper = new Mapper(); |
||
111 | |||
112 | foreach (array_unique($list) as $element) { |
||
113 | if ($classShortcut && strncmp($element, '::', 2) === 0) { |
||
114 | $element = $classShortcut . $element; |
||
115 | } |
||
116 | |||
117 | $element = preg_replace('/[\s()]+$/', '', $element); |
||
118 | $element = explode(' ', $element); |
||
119 | $element = $element[0]; |
||
120 | |||
121 | if ($mode === 'covers' && interface_exists($element)) { |
||
122 | throw new InvalidCoversTargetException( |
||
123 | sprintf( |
||
124 | 'Trying to @cover interface "%s".', |
||
125 | $element |
||
126 | ) |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | try { |
||
131 | $codeUnits = $codeUnits->mergeWith($mapper->stringToCodeUnits($element)); |
||
132 | } catch (InvalidCodeUnitException $e) { |
||
133 | throw new InvalidCoversTargetException( |
||
134 | sprintf( |
||
135 | '"@%s %s" is invalid', |
||
136 | $mode, |
||
137 | $element |
||
138 | ), |
||
139 | (int) $e->getCode(), |
||
140 | $e |
||
141 | ); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | return $mapper->codeUnitsToSourceLines($codeUnits); |
||
146 | } |
||
165 |