Skip to content

Commit

Permalink
fixed issue GH-200 (goto statement)
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed May 12, 2015
1 parent 79ccaf3 commit 28a5b2d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Bartlett/CompatInfo/Analyser/CompatibilityAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ public function leaveNode(Node $node)
) {
$this->computePhpFeatureVersions($node);

} elseif ($node instanceof Node\Stmt\Goto_) {
$this->computePhpFeatureVersions($node);

} elseif ($node instanceof Node\Stmt\Const_) {
foreach ($node->consts as $const) {
// user constant does not require to search in REF database
Expand Down Expand Up @@ -1122,6 +1125,10 @@ private function computePhpFeatureVersions(Node $node)
$versions = array('php.min' => '5.4.0');
$this->updateLocalVersions($versions);
}

} elseif ($node instanceof Node\Stmt\Goto_) {
$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 @@ -41,6 +41,7 @@ class PhpFeaturesIssueTest extends \PHPUnit_Framework_TestCase
const GH148 = 'gh148.php';
const GH154 = 'gh154.php';
const GH168 = 'gh168.php';
const GH200 = 'gh200.php';

protected static $fixtures;
protected static $analyserId;
Expand Down Expand Up @@ -278,4 +279,30 @@ public function testBugGH168()
$constants['FOO']
);
}

/**
* Regression test for feature GH#200
*
* @link https://github.com/llaville/php-compat-info/issues/200
* goto statement is not checked
* @link http://php.net/manual/en/control-structures.goto.php
* @group features
* @return void
*/
public function testFeatureGH200()
{
$dataSource = self::$fixtures . self::GH200;
$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
);
}
}
6 changes: 6 additions & 0 deletions tests/fixtures/gh200.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
goto a;
echo 'Foo';

a:
echo 'Bar';

0 comments on commit 28a5b2d

Please sign in to comment.