Issues (75)

src/Qiniu/Enum/QiniuEnum.php (1 issue)

Severity
1
<?php
2
// @codingStandardsIgnoreStart
3
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
4
5
namespace Qiniu\Enum;
6
7
use MyCLabs\Enum\Enum;
8
9
if (method_exists("MyCLabs\\Enum\\Enum", "from")) {
10
    abstract class QiniuEnum extends Enum
11
    {
12
        // @codingStandardsIgnoreEnd
13
        // @codingStandardsIgnoreStart
14
    }
15
} else {
16
    /**
17
     * poly fill MyCLabs\Enum\Enum::from in low version
18
     *
19
     * @link https://github.com/myclabs/php-enum
20
     */
21
    abstract class QiniuEnum extends Enum
22
    {
23
        // @codingStandardsIgnoreEnd
24
        /**
25
         * @param mixed $value
26
         * @return static
27
         */
28
        public static function from($value)
29
        {
30
            $key = self::assertValidValueReturningKey($value);
31
32
            return self::__callStatic($key, array());
33
        }
34
35
        /**
36
         * Asserts valid enum value
37
         *
38
         * @psalm-pure
39
         * @psalm-assert T $value
40
         * @param mixed $value
41
         * @return string
42
         */
43
        private static function assertValidValueReturningKey($value)
44
        {
45
            if (false === ($key = self::search($value))) {
0 ignored issues
show
The condition false === $key = self::search($value) is always false.
Loading history...
46
                throw new \UnexpectedValueException("Value '$value' is not part of the enum " . __CLASS__);
47
            }
48
49
            return $key;
50
        }
51
        // @codingStandardsIgnoreStart
52
    }
53
}
54