Skip to content

Commit

Permalink
Enhancement: Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored and sebastianbergmann committed Sep 7, 2018
1 parent bc3f2cb commit a578749
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions src/Util/Configuration.php
Expand Up @@ -1104,20 +1104,10 @@ private function getTestSuite(DOMElement $testSuiteNode, string $testSuiteFilter
continue;
}

$phpVersion = \PHP_VERSION;
$phpVersionOperator = '>=';
$prefix = '';
$suffix = 'Test.php';

if ($directoryNode->hasAttribute('phpVersion')) {
$phpVersion = (string) $directoryNode->getAttribute('phpVersion');
}

if ($directoryNode->hasAttribute('phpVersionOperator')) {
$phpVersionOperator = (string) $directoryNode->getAttribute('phpVersionOperator');
}
$prefix = '';
$suffix = 'Test.php';

if (!\version_compare(\PHP_VERSION, $phpVersion, $phpVersionOperator)) {
if (!$this->satisfiesPhpVersion($directoryNode)) {
continue;
}

Expand Down Expand Up @@ -1159,19 +1149,9 @@ private function getTestSuite(DOMElement $testSuiteNode, string $testSuiteFilter
continue;
}

$file = $file[0];
$phpVersion = \PHP_VERSION;
$phpVersionOperator = '>=';

if ($fileNode->hasAttribute('phpVersion')) {
$phpVersion = (string) $fileNode->getAttribute('phpVersion');
}

if ($fileNode->hasAttribute('phpVersionOperator')) {
$phpVersionOperator = (string) $fileNode->getAttribute('phpVersionOperator');
}
$file = $file[0];

if (!\version_compare(\PHP_VERSION, $phpVersion, $phpVersionOperator)) {
if (!$this->satisfiesPhpVersion($fileNode)) {
continue;
}

Expand All @@ -1181,6 +1161,22 @@ private function getTestSuite(DOMElement $testSuiteNode, string $testSuiteFilter
return $suite;
}

private function satisfiesPhpVersion(DOMElement $node): bool
{
$phpVersion = \PHP_VERSION;
$phpVersionOperator = '>=';

if ($node->hasAttribute('phpVersion')) {
$phpVersion = (string) $node->getAttribute('phpVersion');
}

if ($node->hasAttribute('phpVersionOperator')) {
$phpVersionOperator = (string) $node->getAttribute('phpVersionOperator');
}

return \version_compare(\PHP_VERSION, $phpVersion, $phpVersionOperator);
}

/**
* if $value is 'false' or 'true', this returns the value that $value represents.
* Otherwise, returns $default, which may be a string in rare cases.
Expand Down

0 comments on commit a578749

Please sign in to comment.