1 | <?php |
||
14 | class OperationObject |
||
15 | { |
||
16 | /** |
||
17 | * @var SwaggerDocument |
||
18 | */ |
||
19 | private $document; |
||
20 | |||
21 | /** |
||
22 | * @var object |
||
23 | */ |
||
24 | private $definition; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $path; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $method; |
||
35 | |||
36 | /** |
||
37 | * @param SwaggerDocument $document |
||
38 | * @param string $path |
||
39 | * @param string $method |
||
40 | */ |
||
41 | public function __construct(SwaggerDocument $document, $path, $method) |
||
42 | { |
||
43 | $paths = $document->getPathDefinitions(); |
||
44 | |||
45 | if (!property_exists($paths, $path)) { |
||
46 | throw new \InvalidArgumentException("Path '$path' not in Swagger document"); |
||
47 | } |
||
48 | $method = strtolower($method); |
||
49 | if (!property_exists($paths->$path, $method)) { |
||
50 | throw new \InvalidArgumentException("Method '$method' not supported for path '$path'"); |
||
51 | } |
||
52 | |||
53 | $this->document = $document; |
||
54 | $this->path = $path; |
||
55 | $this->method = $method; |
||
56 | $this->definition = $paths->$path->$method; |
||
57 | $this->definition->{'x-request-schema'} = $this->assembleRequestSchema(); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param object $definition |
||
62 | * @param string $path |
||
63 | * @param string $method |
||
64 | * |
||
65 | * @return static |
||
66 | */ |
||
67 | public static function createFromOperationDefinition($definition, $path = '/', $method = 'GET') |
||
68 | { |
||
69 | $method = strtolower($method); |
||
70 | $documentDefinition = (object)[ |
||
71 | 'paths' => (object)[ |
||
72 | $path => (object)[ |
||
73 | $method => $definition |
||
74 | ] |
||
75 | ] |
||
76 | ]; |
||
77 | $document = new SwaggerDocument('', $documentDefinition); |
||
78 | |||
79 | return new static($document, $path, $method); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return object |
||
84 | */ |
||
85 | public function getRequestSchema() |
||
89 | |||
90 | /** |
||
91 | * @return bool |
||
92 | */ |
||
93 | public function hasParameters() |
||
97 | |||
98 | /** |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getParameters() |
||
102 | { |
||
103 | return $this->hasParameters() ? $this->definition->parameters : []; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return string |
||
108 | */ |
||
109 | public function getPath() |
||
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getMethod() |
||
121 | |||
122 | /** |
||
123 | * @return object |
||
124 | */ |
||
125 | public function getDefinition() |
||
129 | |||
130 | /** |
||
131 | * @param string $parameterName |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function createParameterPointer($parameterName) |
||
150 | |||
151 | /** |
||
152 | * @param string $parameterName |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function createParameterSchemaPointer($parameterName) |
||
179 | |||
180 | /** |
||
181 | * @param string $pointer |
||
182 | * @param array $segments |
||
183 | * @param object $context |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public static function resolvePointerRecursively($pointer, array $segments, $context) |
||
201 | |||
202 | /** |
||
203 | * @return object |
||
204 | */ |
||
205 | private function assembleRequestSchema() |
||
240 | } |
||
241 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.