Method::parse()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Dontdrinkandroot\RestBundle\Metadata\Annotation;
4
5
use Doctrine\Common\Annotations\Annotation\Required;
6
7
/**
8
 * @author Philip Washington Sorst <[email protected]>
9
 *
10
 * @Annotation
11
 * @Target({"ANNOTATION"})
12
 */
13
class Method
14
{
15
    const LIST = 'LIST';
16
    const POST = 'POST';
17
    const GET = 'GET';
18
    const PUT = 'PUT';
19
    const DELETE = 'DELETE';
20
21
    /**
22
     * @Required()
23
     * @var string
24
     */
25
    public $name;
26
27
    /**
28
     * @var \Dontdrinkandroot\RestBundle\Metadata\Annotation\Right
29
     */
30
    public $right;
31
32
    /**
33
     * @var array<string>
34
     */
35
    public $defaultIncludes;
36
37 54
    public static function parse($name, $config): ?Method
38
    {
39 54
        assert(in_array($name, [self::LIST, self::POST, self::GET, self::PUT, self::DELETE]));
40 54
        assert(is_string($name));
41
42 54
        $method = new Method();
43 54
        $method->name = $name;
44 54
        if (is_bool($config) && true === $config) {
45 30
            return $method;
46
        }
47
48 54
        $method->right = Right::parse($config['right'] ?? null);
49 54
        $method->defaultIncludes = ParseUtils::parseStringArray($config['defaultIncludes'] ?? null);
50
51 54
        return $method;
52
    }
53
}
54