From 1dc2bdc14675fd99baa3e9843df58ef2f88f0241 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Mon, 16 Jan 2017 21:53:32 +0100 Subject: [PATCH] FIX gh-227 issue --- .../Analyser/CompatibilityAnalyser.php | 9 +++++++ tests/PhpFeaturesIssueTest.php | 25 +++++++++++++++++++ tests/fixtures/gh227.php | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 tests/fixtures/gh227.php diff --git a/src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php b/src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php index e079d5c5..8a34086a 100644 --- a/src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php +++ b/src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php @@ -295,6 +295,9 @@ public function leaveNode(Node $node) } elseif ($node instanceof Node\Stmt\Use_) { $this->computePhpFeatureVersions($node); + } elseif ($node instanceof Node\Stmt\TraitUse) { + $this->computePhpFeatureVersions($node); + } elseif ($node instanceof Node\Stmt\Property) { $this->computePhpFeatureVersions($node); @@ -1178,6 +1181,12 @@ private function computePhpFeatureVersions(Node $node) $this->updateContextVersion($versions); } + } elseif ($node instanceof Node\Stmt\TraitUse) { + $versions = array('php.min' => '5.4.0'); + // update current and parent context + $this->updateElementVersion($element, $name, $versions); + $this->updateContextVersion($versions); + } elseif ($node instanceof Node\Stmt\Property) { // implicitly public visibility is PHP 4 syntax if ($this->isImplicitlyPublicProperty($this->tokens, $node)) { diff --git a/tests/PhpFeaturesIssueTest.php b/tests/PhpFeaturesIssueTest.php index db83f3c1..a5539729 100644 --- a/tests/PhpFeaturesIssueTest.php +++ b/tests/PhpFeaturesIssueTest.php @@ -49,6 +49,7 @@ class PhpFeaturesIssueTest extends \PHPUnit_Framework_TestCase const GH218 = 'gh218.php'; const GH222 = 'gh222.php'; const GH226 = 'gh226.php'; + const GH227 = 'gh227.php'; protected static $fixtures; protected static $analyserId; @@ -487,4 +488,28 @@ public function testFeatureGH226() $versions ); } + + /** + * Regression test for feature GH#227 + * + * @link https://github.com/llaville/php-compat-info/issues/227 + * Does not detect Use traits + * @group features + * @return void + */ + public function testFeatureGH227() + { + $dataSource = self::$fixtures . self::GH227; + $analysers = array('compatibility'); + $metrics = self::$api->run($dataSource, $analysers); + $versions = $metrics[self::$analyserId]['versions']; + $this->assertEquals( + array( + 'php.min' => '5.4.0', + 'php.max' => '', + 'php.all' => '5.4.0', + ), + $versions + ); + } } diff --git a/tests/fixtures/gh227.php b/tests/fixtures/gh227.php new file mode 100644 index 00000000..38e79960 --- /dev/null +++ b/tests/fixtures/gh227.php @@ -0,0 +1,2 @@ +