Completed
Push — master ( 386146...a2d301 )
by John
07:40
created

SwaggerDocument::resolveSelfReferences()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 5
eloc 11
nc 5
nop 2
1
<?php
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 Symfony\Component\Yaml\Yaml;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class SwaggerDocument
17
{
18
    /**
19
     * @var string
20
     */
21
    private $uri;
22
23
    /**
24
     * @var object
25
     */
26
    private $definition;
27
28
    /**
29
     * @param string $pathFileName
30
     * @param object $definition
31
     */
32
    public function __construct($pathFileName, $definition)
33
    {
34
        $this->uri = $pathFileName;
35
        $this->definition = $definition;
36
    }
37
38
    /**
39
     * @return object
40
     */
41
    public function getDefinition()
42
    {
43
        return $this->definition;
44
    }
45
46
    /**
47
     * @return object
48
     */
49
    public function getPathDefinitions()
50
    {
51
        return $this->definition->paths;
52
    }
53
54
    /**
55
     * @return object
56
     */
57
    public function getResourceSchemas()
58
    {
59
        return $this->definition->definitions;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getBasePath()
66
    {
67
        return $this->definition->basePath;
68
    }
69
70
    /**
71
     * @param string $path
72
     * @param string $method
73
     *
74
     * @return object
75
     */
76
    public function getOperationDefinition($path, $method)
77
    {
78
        $paths = $this->getPathDefinitions();
79
        if (!property_exists($paths, $path)) {
80
            throw new \InvalidArgumentException("Path '$path' not in Swagger document");
81
        }
82
        $method = strtolower($method);
83
        if (!property_exists($paths->$path, $method)) {
84
            throw new \InvalidArgumentException("Method '$method' not supported for path '$path'");
85
        }
86
87
        return $paths->$path->$method;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getUri()
94
    {
95
        return $this->uri;
96
    }
97
}
98