Completed
Push — master ( e54b6a...c762b0 )
by John
03:11
created

RamlPath::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 3
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions 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\ApiDescriptions\Description\Standard\Raml;
10
11
use KleijnWeb\ApiDescriptions\Description\Operation;
12
use KleijnWeb\ApiDescriptions\Description\Path;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class RamlPath extends Path
18
{
19
    private static $methodNames = [
20
        'get',
21
        'patch',
22
        'put',
23
        'post',
24
        'delete',
25
        'options',
26
        'head'
27
    ];
28
29
    /**
30
     * Path constructor.
31
     *
32
     * @param string    $path
33
     * @param \stdClass $definition
34
     * @param array     $pathParameters
35
     */
36
    public function __construct(string $path, \stdClass $definition, array $pathParameters = [])
37
    {
38
        $this->path = $path;
39
40
        foreach (self::$methodNames as $method) {
41
            if (isset($definition->$method)) {
42
                $this->operations[$method] = $this->createOperation($method, $definition->$method);
43
            }
44
        }
45
46
        $this->pathParameters = array_merge($pathParameters, RamlOperation::extractParameters($definition));
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($pathParamet...arameters($definition)) of type array is incompatible with the declared type array<integer,object<Kle...Description\Parameter>> of property $pathParameters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
    }
48
49
    /**
50
     * @param string    $method
51
     * @param \stdClass $operationDefinition
52
     *
53
     * @return Operation
54
     */
55
    protected function createOperation(string $method, \stdClass $operationDefinition): Operation
56
    {
57
        return new RamlOperation(
58
            $operationDefinition,
59
            $this->getPath(),
60
            $method,
61
            $this->pathParameters
62
        );
63
    }
64
}
65