Completed
Push — master ( fcd315...e54b6a )
by John
02:20
created

Description::getHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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;
10
11
use KleijnWeb\ApiDescriptions\Description\Visitor\Visitee;
12
use KleijnWeb\ApiDescriptions\Description\Visitor\VisiteeMixin;
13
use KleijnWeb\ApiDescriptions\Document\Document;
14
15
/**
16
 * @author John Kleijn <[email protected]>
17
 */
18
abstract class Description implements Visitee
19
{
20
    use VisiteeMixin;
21
22
    /**
23
     * @var Path[]
24
     */
25
    protected $paths;
26
27
    /**
28
     * @var string
29
     */
30
    protected $host;
31
32
    /**
33
     * @var array
34
     */
35
    protected $schemes = [];
36
37
    /**
38
     * @var Document
39
     */
40
    protected $document;
41
42
    /**
43
     * @return array
44
     */
45
    public function getSchemes(): array
46
    {
47
        return $this->schemes;
48
    }
49
50
    /**
51
     * @return string|null
52
     */
53
    public function getHost()
54
    {
55
        return $this->host;
56
    }
57
58
    /**
59
     * @param string $path
60
     *
61
     * @return Path
62
     */
63
    public function getPath(string $path): Path
64
    {
65 View Code Duplication
        if (!isset($this->paths[$path])) {
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...
66
            throw new \InvalidArgumentException(
67
                "Path '$path' does not exist (have " . implode(', ', array_keys($this->paths)) . ')'
68
            );
69
        }
70
71
        return $this->paths[$path];
72
    }
73
74
    /**
75
     * @param string $path
76
     * @param string $method
77
     *
78
     * @return Schema
79
     */
80
    public function getRequestSchema(string $path, string $method): Schema
81
    {
82
        return $this->getPath($path)->getOperation($method)->getRequestSchema();
83
    }
84
85
    /**
86
     * @param string $path
87
     * @param string $method
88
     *
89
     * @param int    $code
90
     *
91
     * @return Schema
92
     */
93
    public function getResponseSchema(string $path, string $method, int $code): Schema
94
    {
95
        return $this->getPath($path)->getOperation($method)->getResponse($code)->getSchema();
96
    }
97
98
    /**
99
     * @return Path[]
100
     */
101
    public function getPaths(): array
102
    {
103
        return array_values($this->paths);
104
    }
105
106
    /**
107
     * @return Document
108
     */
109
    public function getDocument(): Document
110
    {
111
        return $this->document;
112
    }
113
}
114