Test Failed
Push — 7.x ( bea7e1...2b11c5 )
by Adrien
08:51
created

SplReflectionEnumHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 37
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIntReflectionNamedType() 0 8 2
A __construct() 0 2 1
A getStringReflectionNamedType() 0 8 2
1
<?php
2
3
/**
4
 * Part of SplTypes package.
5
 *
6
 * (c) Adrien Loyant <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Ducks\Component\SplTypes\Reflection;
15
16
/**
17
 * The ReflectionEnum class reports information about an Enum.
18
 *
19
 * @link https://php.net/manual/en/class.reflectionenum.php
20
 */
21
final class SplReflectionEnumHelper
22
{
23
    private static ?\ReflectionNamedType $rnts = null;
24
    private static ?\ReflectionNamedType $rnti = null;
25
26
    private function __construct()
27
    {
28
    }
29
30
    /**
31
     * Only way to generate a string ReflectionNamedType (Internal use).
32
     *
33
     * @return \ReflectionNamedType
34
     */
35
    public static function getStringReflectionNamedType(): \ReflectionNamedType
36
    {
37
        if (null === static::$rnts) {
0 ignored issues
show
Bug introduced by
Since $rnts is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $rnts to at least protected.
Loading history...
38
            $func = new \ReflectionFunction(static fn(string $param): string => $param);
39
            static::$rnts = ($func->getParameters()[0])->getType();
40
        }
41
42
        return static::$rnts;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::rnts could return the type null which is incompatible with the type-hinted return ReflectionNamedType. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
45
    /**
46
     * Only way to generate an int ReflectionNamedType (Internal use).
47
     *
48
     * @return \ReflectionNamedType
49
     */
50
    public static function getIntReflectionNamedType(): \ReflectionNamedType
51
    {
52
        if (null === static::$rnti) {
0 ignored issues
show
Bug introduced by
Since $rnti is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $rnti to at least protected.
Loading history...
53
            $func = new \ReflectionFunction(static fn(int $param): int => $param);
54
            static::$rnti = ($func->getParameters()[0])->getType();
55
        }
56
57
        return static::$rnti;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::rnti could return the type null which is incompatible with the type-hinted return ReflectionNamedType. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
}
60