Skip to content

Commit

Permalink
fixed issue GH-213 about PHP 5.3 feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Dec 3, 2015
1 parent 3220285 commit 1ec0604
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ public function leaveNode(Node $node)
) {
$this->computeClassMethodCallVersions($node);

} elseif ($node instanceof Node\Expr\StaticCall
&& $node->class instanceof Node\Expr\Variable
) {
$this->computePhpFeatureVersions($node);

} elseif ($node instanceof Node\Expr\StaticCall
&& is_string($node->name)
) {
Expand Down Expand Up @@ -1146,6 +1151,11 @@ private function computePhpFeatureVersions(Node $node)
$this->updateLocalVersions($versions);
}

} elseif ($node instanceof Node\Expr\StaticCall
&& $node->class instanceof Node\Expr\Variable
) {
$versions = array('php.min' => '5.3.0');
$this->updateLocalVersions($versions);
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/PhpFeaturesIssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PhpFeaturesIssueTest extends \PHPUnit_Framework_TestCase
const GH168 = 'gh168.php';
const GH200 = 'gh200.php';
const GH207 = 'gh207.php';
const GH213 = 'gh213.php';

protected static $fixtures;
protected static $analyserId;
Expand Down Expand Up @@ -332,4 +333,30 @@ public function testFeatureGH207()
$versions
);
}

/**
* Regression test for feature GH#213
*
* @link https://github.com/llaville/php-compat-info/issues/213
* Dynamic access to static methods and properties are not detected
* @link http://php.net/manual/en/migration53.new-features.php
* @group features
* @return void
*/
public function testFeatureGH213()
{
$dataSource = self::$fixtures . self::GH213;
$analysers = array('compatibility');
$metrics = self::$api->run($dataSource, $analysers);
$versions = $metrics[self::$analyserId]['versions'];

$this->assertEquals(
array(
'php.min' => '5.3.0',
'php.max' => '',
'php.all' => '5.3.0',
),
$versions
);
}
}
13 changes: 13 additions & 0 deletions tests/fixtures/gh213.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class MyClass {
public static $t = 't';
public static function test() {
//Do something
}
}

$name = 'MyClass';

//Following lines are supported only in PHP 5.3+
$name::test();
echo $name::$t;

0 comments on commit 1ec0604

Please sign in to comment.