Skip to content

Commit

Permalink
FIX gh-227 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Jan 16, 2017
1 parent 3a1f6b0 commit 1dc2bdc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/PhpFeaturesIssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
2 changes: 2 additions & 0 deletions tests/fixtures/gh227.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
class A { use B; }

0 comments on commit 1dc2bdc

Please sign in to comment.