-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exporting Enums when using PHP8.1+
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\VarExporter\Internal\ObjectExporter; | ||
|
||
use Brick\VarExporter\Internal\ObjectExporter; | ||
use UnitEnum; | ||
|
||
/** | ||
* Handles enums. | ||
* | ||
* @internal This class is for internal use, and not part of the public API. It may change at any time without warning. | ||
*/ | ||
class EnumExporter extends ObjectExporter | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* | ||
* See: https://github.com/vimeo/psalm/pull/8117 | ||
* @psalm-suppress MixedInferredReturnType | ||
* @psalm-suppress MixedReturnStatement | ||
*/ | ||
public function supports(\ReflectionObject $reflectionObject) : bool | ||
{ | ||
if (! method_exists($reflectionObject, 'isEnum')) { | ||
return false; | ||
} | ||
|
||
return $reflectionObject->isEnum(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function export(object $object, \ReflectionObject $reflectionObject, array $path, array $parentIds) : array | ||
{ | ||
assert($object instanceof UnitEnum); | ||
|
||
return [ | ||
get_class($object) . '::' . $object->name | ||
]; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\VarExporter\Tests\Classes; | ||
|
||
enum Enum | ||
{ | ||
case TEST; | ||
} |
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