Completed
Push — master ( bca24d...1b0d8b )
by John
03:18
created

Path::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\PhpApi\Descriptions\Description;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Visitor\VisiteeMixin;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class Path implements Element
17
{
18
    use VisiteeMixin;
19
20
    /**
21
     * @var string
22
     */
23
    protected $path;
24
25
    /**
26
     * @var Operation[]
27
     */
28
    protected $operations = [];
29
30
    /**
31
     * @var Parameter[]
32
     */
33
    protected $pathParameters = [];
34
35
    /**
36
     * Path constructor.
37
     *
38
     * @param string      $path
39
     * @param Operation[] $operations
40
     * @param Parameter[] $pathParameters
41
     */
42
    public function __construct($path, array $operations, array $pathParameters)
43
    {
44
        $this->path           = $path;
45
        $this->operations     = $operations;
46
        $this->pathParameters = $pathParameters;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getPath(): string
53
    {
54
        return $this->path;
55
    }
56
57
    /**
58
     * @return Operation[]
59
     */
60
    public function getOperations(): array
61
    {
62
        return $this->operations;
63
    }
64
65
    /**
66
     * @param string $method
67
     *
68
     * @return Operation
69
     */
70
    public function getOperation(string $method): Operation
71
    {
72
        $method = strtolower($method);
73
74 View Code Duplication
        if (!isset($this->operations[$method])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
            throw new \InvalidArgumentException(
76
                "Path '{$this->getPath()}' does not support '$method'" .
77
                " (supports " . implode(', ', array_keys($this->operations)) . ')'
78
            );
79
        }
80
81
        return $this->operations[$method];
82
    }
83
84
    /**
85
     * @return Parameter[]
86
     */
87
    public function getPathParameters(): array
88
    {
89
        return $this->pathParameters;
90
    }
91
}
92