-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
213 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
||
class EnumTest extends BaseTestCase | ||
{ | ||
public function testEnum() | ||
{ | ||
$fixtureFile = $this->getFixture('EnumFixture.php'); | ||
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); | ||
$phpcsFile->process(); | ||
$lines = $this->getWarningLineNumbersFromFile($phpcsFile); | ||
$expectedWarnings = [ | ||
33, | ||
]; | ||
$this->assertEquals($expectedWarnings, $lines); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
enum Suit | ||
{ | ||
case Hearts; | ||
case Diamonds; | ||
case Clubs; | ||
case Spades; | ||
} | ||
|
||
enum BackedSuit: string | ||
{ | ||
case Hearts = 'H'; | ||
case Diamonds = 'D'; | ||
case Clubs = 'C'; | ||
case Spades = 'S'; | ||
} | ||
|
||
enum Numbers: string { | ||
case ONE = '1'; | ||
case TWO = '2'; | ||
case THREE = '3'; | ||
case FOUR = '4'; | ||
|
||
public function divisibility(): string { | ||
return match ($this) { | ||
self::ONE, self::THREE => 'odd', | ||
self::TWO, self::FOUR => 'even', | ||
}; | ||
} | ||
|
||
public function foobar(): string { | ||
return match ($foo) { // undefined variable $foo | ||
'x' => 'first', | ||
'y' => 'second', | ||
default => 'unknown', | ||
}; | ||
} | ||
} |
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 | ||
|
||
namespace VariableAnalysis\Lib; | ||
|
||
/** | ||
* Holds details of an enum. | ||
*/ | ||
class EnumInfo | ||
{ | ||
/** | ||
* The position of the `enum` token. | ||
* | ||
* @var int | ||
*/ | ||
public $enumIndex; | ||
|
||
/** | ||
* The position of the block opener (curly brace) for the enum. | ||
* | ||
* @var int | ||
*/ | ||
public $blockStart; | ||
|
||
/** | ||
* The position of the block closer (curly brace) for the enum. | ||
* | ||
* @var int | ||
*/ | ||
public $blockEnd; | ||
|
||
/** | ||
* @param int $enumIndex | ||
* @param int $blockStart | ||
* @param int $blockEnd | ||
*/ | ||
public function __construct( | ||
$enumIndex, | ||
$blockStart, | ||
$blockEnd | ||
) { | ||
$this->enumIndex = $enumIndex; | ||
$this->blockStart = $blockStart; | ||
$this->blockEnd = $blockEnd; | ||
} | ||
} |
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