| Conditions | 70 |
| Paths | 1820 |
| Total Lines | 132 |
| Code Lines | 101 |
| 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 |
||
| 166 | private function parseConstraint($constraint) |
||
| 167 | { |
||
| 168 | if (\preg_match('{^([^,\\s]++) ++as ++([^,\\s]++)$}', $constraint, $match)) { |
||
| 169 | $constraint = $match[1]; |
||
| 170 | } |
||
| 171 | if (\preg_match('{^([^,\\s]*?)@(' . self::$stabilitiesRegex . ')$}i', $constraint, $match)) { |
||
| 172 | $constraint = '' !== $match[1] ? $match[1] : '*'; |
||
| 173 | if ($match[2] !== 'stable') { |
||
| 174 | $stabilityModifier = $match[2]; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | if (\preg_match('{^(dev-[^,\\s@]+?|[^,\\s@]+?\\.x-dev)#.+$}i', $constraint, $match)) { |
||
| 178 | $constraint = $match[1]; |
||
| 179 | } |
||
| 180 | if (\preg_match('{^(v)?[xX*](\\.[xX*])*$}i', $constraint, $match)) { |
||
| 181 | if (!empty($match[1]) || !empty($match[2])) { |
||
| 182 | return array(new Constraint('>=', '0.0.0.0-dev')); |
||
| 183 | } |
||
| 184 | return array(new MatchAllConstraint()); |
||
| 185 | } |
||
| 186 | $versionRegex = 'v?(\\d++)(?:\\.(\\d++))?(?:\\.(\\d++))?(?:\\.(\\d++))?(?:' . self::$modifierRegex . '|\\.([xX*][.-]?dev))(?:\\+[^\\s]+)?'; |
||
| 187 | if (\preg_match('{^~>?' . $versionRegex . '$}i', $constraint, $matches)) { |
||
| 188 | if (\strpos($constraint, '~>') === 0) { |
||
| 189 | throw new \UnexpectedValueException('Could not parse version constraint ' . $constraint . ': ' . 'Invalid operator "~>", you probably meant to use the "~" operator'); |
||
| 190 | } |
||
| 191 | if (isset($matches[4]) && '' !== $matches[4] && null !== $matches[4]) { |
||
| 192 | $position = 4; |
||
| 193 | } elseif (isset($matches[3]) && '' !== $matches[3] && null !== $matches[3]) { |
||
| 194 | $position = 3; |
||
| 195 | } elseif (isset($matches[2]) && '' !== $matches[2] && null !== $matches[2]) { |
||
| 196 | $position = 2; |
||
| 197 | } else { |
||
| 198 | $position = 1; |
||
| 199 | } |
||
| 200 | if (!empty($matches[8])) { |
||
| 201 | $position++; |
||
| 202 | } |
||
| 203 | $stabilitySuffix = ''; |
||
| 204 | if (empty($matches[5]) && empty($matches[7]) && empty($matches[8])) { |
||
| 205 | $stabilitySuffix .= '-dev'; |
||
| 206 | } |
||
| 207 | $lowVersion = $this->normalize(\substr($constraint . $stabilitySuffix, 1)); |
||
| 208 | $lowerBound = new Constraint('>=', $lowVersion); |
||
| 209 | $highPosition = \max(1, $position - 1); |
||
| 210 | $highVersion = $this->manipulateVersionString($matches, $highPosition, 1) . '-dev'; |
||
| 211 | $upperBound = new Constraint('<', $highVersion); |
||
| 212 | return array($lowerBound, $upperBound); |
||
| 213 | } |
||
| 214 | if (\preg_match('{^\\^' . $versionRegex . '($)}i', $constraint, $matches)) { |
||
| 215 | if ('0' !== $matches[1] || '' === $matches[2] || null === $matches[2]) { |
||
| 216 | $position = 1; |
||
| 217 | } elseif ('0' !== $matches[2] || '' === $matches[3] || null === $matches[3]) { |
||
| 218 | $position = 2; |
||
| 219 | } else { |
||
| 220 | $position = 3; |
||
| 221 | } |
||
| 222 | $stabilitySuffix = ''; |
||
| 223 | if (empty($matches[5]) && empty($matches[7]) && empty($matches[8])) { |
||
| 224 | $stabilitySuffix .= '-dev'; |
||
| 225 | } |
||
| 226 | $lowVersion = $this->normalize(\substr($constraint . $stabilitySuffix, 1)); |
||
| 227 | $lowerBound = new Constraint('>=', $lowVersion); |
||
| 228 | $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev'; |
||
| 229 | $upperBound = new Constraint('<', $highVersion); |
||
| 230 | return array($lowerBound, $upperBound); |
||
| 231 | } |
||
| 232 | if (\preg_match('{^v?(\\d++)(?:\\.(\\d++))?(?:\\.(\\d++))?(?:\\.[xX*])++$}', $constraint, $matches)) { |
||
| 233 | if (isset($matches[3]) && '' !== $matches[3] && null !== $matches[3]) { |
||
| 234 | $position = 3; |
||
| 235 | } elseif (isset($matches[2]) && '' !== $matches[2] && null !== $matches[2]) { |
||
| 236 | $position = 2; |
||
| 237 | } else { |
||
| 238 | $position = 1; |
||
| 239 | } |
||
| 240 | $lowVersion = $this->manipulateVersionString($matches, $position) . '-dev'; |
||
| 241 | $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev'; |
||
| 242 | if ($lowVersion === '0.0.0.0-dev') { |
||
| 243 | return array(new Constraint('<', $highVersion)); |
||
| 244 | } |
||
| 245 | return array(new Constraint('>=', $lowVersion), new Constraint('<', $highVersion)); |
||
| 246 | } |
||
| 247 | if (\preg_match('{^(?P<from>' . $versionRegex . ') +- +(?P<to>' . $versionRegex . ')($)}i', $constraint, $matches)) { |
||
| 248 | $lowStabilitySuffix = ''; |
||
| 249 | if (empty($matches[6]) && empty($matches[8]) && empty($matches[9])) { |
||
| 250 | $lowStabilitySuffix = '-dev'; |
||
| 251 | } |
||
| 252 | $lowVersion = $this->normalize($matches['from']); |
||
| 253 | $lowerBound = new Constraint('>=', $lowVersion . $lowStabilitySuffix); |
||
| 254 | $empty = function ($x) { |
||
| 255 | return $x === 0 || $x === '0' ? \false : empty($x); |
||
| 256 | }; |
||
| 257 | if (!$empty($matches[12]) && !$empty($matches[13]) || !empty($matches[15]) || !empty($matches[17]) || !empty($matches[18])) { |
||
| 258 | $highVersion = $this->normalize($matches['to']); |
||
| 259 | $upperBound = new Constraint('<=', $highVersion); |
||
| 260 | } else { |
||
| 261 | $highMatch = array('', $matches[11], $matches[12], $matches[13], $matches[14]); |
||
| 262 | $this->normalize($matches['to']); |
||
| 263 | $highVersion = $this->manipulateVersionString($highMatch, $empty($matches[12]) ? 1 : 2, 1) . '-dev'; |
||
| 264 | $upperBound = new Constraint('<', $highVersion); |
||
| 265 | } |
||
| 266 | return array($lowerBound, $upperBound); |
||
| 267 | } |
||
| 268 | if (\preg_match('{^(<>|!=|>=?|<=?|==?)?\\s*(.*)}', $constraint, $matches)) { |
||
| 269 | try { |
||
| 270 | try { |
||
| 271 | $version = $this->normalize($matches[2]); |
||
| 272 | } catch (\UnexpectedValueException $e) { |
||
| 273 | if (\substr($matches[2], -4) === '-dev' && \preg_match('{^[0-9a-zA-Z-./]+$}', $matches[2])) { |
||
| 274 | $version = $this->normalize('dev-' . \substr($matches[2], 0, -4)); |
||
| 275 | } else { |
||
| 276 | throw $e; |
||
| 277 | } |
||
| 278 | } |
||
| 279 | $op = $matches[1] ?: '='; |
||
| 280 | if ($op !== '==' && $op !== '=' && !empty($stabilityModifier) && self::parseStability($version) === 'stable') { |
||
| 281 | $version .= '-' . $stabilityModifier; |
||
| 282 | } elseif ('<' === $op || '>=' === $op) { |
||
| 283 | if (!\preg_match('/-' . self::$modifierRegex . '$/', \strtolower($matches[2]))) { |
||
| 284 | if (\strpos($matches[2], 'dev-') !== 0) { |
||
| 285 | $version .= '-dev'; |
||
| 286 | } |
||
| 287 | } |
||
| 288 | } |
||
| 289 | return array(new Constraint($matches[1] ?: '=', $version)); |
||
| 290 | } catch (\Exception $e) { |
||
| 291 | } |
||
| 292 | } |
||
| 293 | $message = 'Could not parse version constraint ' . $constraint; |
||
| 294 | if (isset($e)) { |
||
| 295 | $message .= ': ' . $e->getMessage(); |
||
| 296 | } |
||
| 297 | throw new \UnexpectedValueException($message); |
||
| 298 | } |
||
| 338 |