-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 additions
and
18 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
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
32 changes: 32 additions & 0 deletions
32
src/PHPStan/Constants/BitmaskModifierConstantAlwaysUsed.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,32 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\PHPStan\Constants; | ||
|
||
use Henzeb\Enumhancer\Helpers\EnumImplements; | ||
use PHPStan\Reflection\ConstantReflection; | ||
use PHPStan\Rules\Constants\AlwaysUsedClassConstantsExtension; | ||
use function strtolower; | ||
|
||
class BitmaskModifierConstantAlwaysUsed implements AlwaysUsedClassConstantsExtension | ||
{ | ||
|
||
public function isAlwaysUsed(ConstantReflection $constant): bool | ||
{ | ||
if ($constant->getName() !== strtolower('bit_modifier')) { | ||
return false; | ||
} | ||
|
||
$class = $constant->getDeclaringClass(); | ||
|
||
if (!$class->hasConstant('BIT_VALUES')) { | ||
return false; | ||
} | ||
|
||
if (!$class->getBackedEnumType()?->isInteger()) { | ||
return false; | ||
} | ||
|
||
|
||
return EnumImplements::bitmasks($class->getName()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/Fixtures/BackedEnums/Bitmasks/BitmasksCorrectModifierEnum.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,19 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\Tests\Fixtures\BackedEnums\Bitmasks; | ||
|
||
use Henzeb\Enumhancer\Concerns\Bitmasks; | ||
|
||
enum BitmasksCorrectModifierEnum: int | ||
{ | ||
use Bitmasks; | ||
|
||
const BIT_VALUES = true; | ||
|
||
const BIT_MODIFIER = true; | ||
|
||
case Neither = 1; | ||
case Read = 2; | ||
case Write = 4; | ||
case Both = 6; | ||
} |
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