-
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.
use ShortTernaryOperatorSniff to detect elvis syntax and move gh-211 …
…unit test case
- Loading branch information
Showing
9 changed files
with
105 additions
and
85 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
30 changes: 30 additions & 0 deletions
30
src/Bartlett/CompatInfo/Sniffs/Operators/ShortTernaryOperatorSniff.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,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bartlett\CompatInfo\Sniffs\Operators; | ||
|
||
use Bartlett\CompatInfo\Sniffs\SniffAbstract; | ||
|
||
use PhpParser\Node; | ||
|
||
/** | ||
* Use of Elvis syntax (middle portion of ternary operator missing) since PHP 5.3 | ||
* | ||
* @since https://www.php.net/manual/en/migration53.php | ||
* @since https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary | ||
*/ | ||
class ShortTernaryOperatorSniff extends SniffAbstract | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function leaveNode(Node $node) | ||
{ | ||
if (!$node instanceof Node\Expr\Ternary) { | ||
return null; | ||
} | ||
|
||
if (null === $node->if) { | ||
$this->updateNodeElementVersion($node, $this->attributeKeyStore, ['php.min' => '5.3.0']); | ||
} | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
src/Bartlett/CompatInfo/Sniffs/PHP/ShortTernaryOperatorSyntaxSniff.php
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bartlett\Tests\CompatInfo\Sniffs; | ||
|
||
class ShortTernaryOperatorSniffTest extends SniffTestCase | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
self::$fixtures .= 'operators' . DIRECTORY_SEPARATOR; | ||
} | ||
|
||
/** | ||
* Regression test for short ternary operator (Elvis syntax) | ||
* | ||
* @group features | ||
* @return void | ||
*/ | ||
public function testElvisSyntax() | ||
{ | ||
$dataSource = self::$fixtures . 'elvis_syntax.php'; | ||
$analysers = ['compatibility']; | ||
$metrics = self::$api->run($dataSource, $analysers); | ||
$versions = $metrics[self::$analyserId]['versions']; | ||
|
||
$this->assertEquals( | ||
'5.3.0', | ||
$versions['php.min'] | ||
); | ||
$this->assertEquals( | ||
'', | ||
$versions['php.max'] | ||
); | ||
} | ||
|
||
} |
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,3 @@ | ||
<?php | ||
echo 0 ?: 1 ?: 2 ?: 3; // output: 1 | ||
echo PHP_EOL; |
File renamed without changes.