| 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 |
||
| 104 | private function getLinesToBeCoveredOrUsed(string $className, string $methodName, string $mode): array |
||
| 105 | { |
||
| 106 | $annotations = $this->parseTestMethodAnnotations( |
||
| 107 | $className, |
||
| 108 | $methodName |
||
| 109 | ); |
||
| 110 | |||
| 111 | $classShortcut = null; |
||
| 112 | |||
| 113 | if (!empty($annotations['class'][$mode . 'DefaultClass'])) { |
||
| 114 | if (count($annotations['class'][$mode . 'DefaultClass']) > 1) { |
||
| 115 | throw new CodeCoverageException( |
||
| 116 | sprintf( |
||
| 117 | 'More than one @%sClass annotation in class or interface "%s".', |
||
| 118 | $mode, |
||
| 119 | $className |
||
| 120 | ) |
||
| 121 | ); |
||
| 122 | } |
||
| 123 | |||
| 124 | $classShortcut = $annotations['class'][$mode . 'DefaultClass'][0]; |
||
| 125 | } |
||
| 126 | |||
| 127 | $list = $annotations['class'][$mode] ?? []; |
||
| 128 | |||
| 129 | if (isset($annotations['method'][$mode])) { |
||
| 130 | $list = array_merge($list, $annotations['method'][$mode]); |
||
| 131 | } |
||
| 132 | |||
| 133 | $codeUnits = CodeUnitCollection::fromArray([]); |
||
| 134 | $mapper = new Mapper(); |
||
| 135 | |||
| 136 | foreach (array_unique($list) as $element) { |
||
| 137 | if ($classShortcut && strncmp($element, '::', 2) === 0) { |
||
| 138 | $element = $classShortcut . $element; |
||
| 139 | } |
||
| 140 | |||
| 141 | $element = preg_replace('/[\s()]+$/', '', $element); |
||
| 142 | $element = explode(' ', $element); |
||
| 143 | $element = $element[0]; |
||
| 144 | |||
| 145 | if ('covers' === $mode && interface_exists($element)) { |
||
| 146 | throw new InvalidCoversTargetException( |
||
| 147 | sprintf( |
||
| 148 | 'Trying to @cover interface "%s".', |
||
| 149 | $element |
||
| 150 | ) |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 154 | try { |
||
| 155 | $codeUnits = $codeUnits->mergeWith($mapper->stringToCodeUnits($element)); |
||
| 156 | } catch (InvalidCodeUnitException $e) { |
||
| 157 | throw new InvalidCoversTargetException( |
||
| 158 | sprintf( |
||
| 159 | '"@%s %s" is invalid', |
||
| 160 | $mode, |
||
| 161 | $element |
||
| 162 | ), |
||
| 163 | (int) $e->getCode(), |
||
| 164 | $e |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | return $mapper->codeUnitsToSourceLines($codeUnits); |
||
| 170 | } |
||
| 192 |