Completed
Pull Request — master (#80)
by John
07:39 queued 04:25
created

Specification   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDefinition() 0 4 1
A getPaths() 0 4 1
A getOperation() 0 10 2
A getOperationDefinition() 0 4 1
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle 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\SwaggerBundle\Document;
10
11
use KleijnWeb\SwaggerBundle\Document\Specification\Operation;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class Specification
17
{
18
    /**
19
     * @var object
20
     */
21
    private $definition;
22
23
    /**
24
     * @var Operation[]
25
     */
26
    private $operations;
27
28
    /**
29
     * @param \stdClass $definition
30
     */
31
    public function __construct(\stdClass $definition)
32
    {
33
        $this->definition = $definition;
34
    }
35
36
    /**
37
     * @return \stdClass
38
     */
39
    public function getDefinition(): \stdClass
40
    {
41
        return $this->definition;
42
    }
43
44
    /**
45
     * @return \stdClass
46
     */
47
    public function getPaths(): \stdClass
48
    {
49
        return $this->definition->paths;
50
    }
51
52
    /**
53
     * @param string $path
54
     * @param string $method
55
     *
56
     * @return Operation
57
     */
58
    public function getOperation(string $path, string $method): Operation
59
    {
60
        $key = "$path::$method";
61
62
        if (isset($this->operations[$key])) {
63
            return $this->operations[$key];
64
        }
65
66
        return $this->operations[$key] = new Operation($this, $path, $method);
67
    }
68
69
    /**
70
     * @deprecated
71
     *
72
     * @param string $path
73
     * @param string $method
74
     *
75
     * @return \stdClass
76
     */
77
    public function getOperationDefinition(string $path, string $method): \stdClass
78
    {
79
        return $this->getOperation($path, $method)->getDefinition();
80
    }
81
}
82