-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UseTraitSniff to solve issue gh-227
- Loading branch information
Showing
7 changed files
with
84 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Bartlett/CompatInfo/Sniffs/UseDeclarations/UseTraitSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bartlett\CompatInfo\Sniffs\UseDeclarations; | ||
|
||
use Bartlett\CompatInfo\Sniffs\SniffAbstract; | ||
|
||
use PhpParser\Node; | ||
|
||
/** | ||
* Use trait is PHP 5.4 or greater | ||
* | ||
* @link https://www.php.net/manual/en/language.oop5.traits.php | ||
*/ | ||
class UseTraitSniff extends SniffAbstract | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function enterNode(Node $node) | ||
{ | ||
if (!$node instanceof Node\Stmt\TraitUse) { | ||
return; | ||
} | ||
|
||
$this->updateNodeElementVersion($node, $this->attributeKeyStore, ['php.min' => '5.4.0']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bartlett\Tests\CompatInfo\Sniffs; | ||
|
||
/** | ||
* @link https://github.com/llaville/php-compat-info/issues/227 | ||
*/ | ||
class UseTraitSniffTest extends SniffTestCase | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
self::$fixtures .= 'traits' . DIRECTORY_SEPARATOR; | ||
} | ||
|
||
/** | ||
* Regression test for use trait detection | ||
* | ||
* @link https://github.com/llaville/php-compat-info/issues/227 | ||
* Does not detect Use traits | ||
* @group features | ||
* @group regression | ||
* @return void | ||
*/ | ||
public function testRegressionGH227() | ||
{ | ||
$dataSource = self::$fixtures . 'gh227.php'; | ||
$analysers = ['compatibility']; | ||
$metrics = self::$api->run($dataSource, $analysers); | ||
$classes = $metrics[self::$analyserId]['classes']; | ||
|
||
$this->assertEquals( | ||
'5.4.0', | ||
$classes['A']['php.min'] | ||
); | ||
$this->assertEquals( | ||
'', | ||
$classes['A']['php.max'] | ||
); | ||
} | ||
} |
File renamed without changes.