1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | use Cerbero\Enum\Enums\Backed; |
||||
6 | use Cerbero\Enum\Services\Generator; |
||||
0 ignored issues
–
show
|
|||||
7 | |||||
8 | use function Cerbero\Enum\enumOutcome; |
||||
9 | use function Cerbero\Enum\fail; |
||||
10 | use function Cerbero\Enum\option; |
||||
11 | use function Cerbero\Enum\runAnnotate; |
||||
12 | use function Cerbero\Enum\runTs; |
||||
13 | use function Cerbero\Enum\succeed; |
||||
14 | |||||
15 | if (! $enum = strtr($arguments[0] ?? '', '/', '\\')) { |
||||
16 | return fail('The name of the enum is missing.'); |
||||
17 | } |
||||
18 | |||||
19 | $force = !! array_intersect(['--force', '-f'], $options); |
||||
20 | |||||
21 | if (enum_exists($enum) && ! $force) { |
||||
0 ignored issues
–
show
The function
enum_exists was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
22 | return succeed("The enum {$enum} already exists."); |
||||
23 | } |
||||
24 | |||||
25 | if (! $cases = array_slice($arguments, 1)) { |
||||
26 | return fail('The cases of the enum are missing.'); |
||||
27 | } |
||||
28 | |||||
29 | try { |
||||
30 | $generator = new Generator($enum, $cases, option('backed', $options)); |
||||
31 | } catch (ValueError) { |
||||
32 | return fail('The option --backed supports only ' . implode(', ', Backed::names())); |
||||
33 | } |
||||
34 | |||||
35 | $typeScript = !! array_intersect(['--typescript', '-t'], $options); |
||||
36 | |||||
37 | return enumOutcome($enum, function () use ($generator, $enum, $force, $typeScript) { |
||||
38 | return $generator->generate($force) |
||||
39 | && runAnnotate($enum, $force) |
||||
40 | && ($typeScript ? runTs($enum, $force) : true); |
||||
41 | }); |
||||
42 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: