From a57874975514eb4467f7262f64722d87ae523812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 7 Sep 2018 17:46:01 +0200 Subject: [PATCH] Enhancement: Extract method --- src/Util/Configuration.php | 46 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php index 270e1ef7e54..0b47fe2ab57 100644 --- a/src/Util/Configuration.php +++ b/src/Util/Configuration.php @@ -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; } @@ -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; } @@ -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.