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

SplEnumTrait::cases()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
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
namespace Ducks\Component\SplTypes;
13
14
/**
15
 * Trait used for enum emulation
16
 *
17
 * @psalm-api
18
 */
19
trait SplEnumTrait
20
{
21
    /**
22
     * Return a new instance of enum
23
     *
24
     * @param string $name
25
     * @param array $arguments
26
     *
27
     * @return static
28
     *
29
     * @psalm-suppress UnsafeInstantiation
30
     * @phpstan-ignore-next-line
31
     */
32
    #[\ReturnTypeWillChange]
33
    public static function __callStatic(string $name, array $arguments)
34
    {
35
        try {
36
            $class = new \ReflectionClassConstant(static::class, $name);
37
        } catch (\ReflectionException $th) {
38
            throw new \Error('Undefined constant ' . static::class . '::' . $name);
39
        }
40
41
        // @phpstan-ignore-next-line
42
        return new static($class->getValue());
0 ignored issues
show
Unused Code introduced by
The call to Ducks\Component\SplTypes...numTrait::__construct() has too many arguments starting with $class->getValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        return /** @scrutinizer ignore-call */ new static($class->getValue());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
43
    }
44
}
45