Parameter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 1
1
<?php
2
3
namespace erasys\OpenApi\Spec\v3;
4
5
/**
6
 * Describes a single operation parameter.
7
 * A unique parameter is defined by a combination of a name and location.
8
 *
9
 * Parameter Locations
10
 * There are four possible parameter locations specified by the in field:
11
 *
12
 * - path: Used together with Path Templating, where the parameter value is actually part of the operation's URL. This
13
 * does not include the host or base path of the API. For example, in /items/{itemId}, the path parameter is itemId.
14
 *
15
 * - query: Parameters that are appended to the URL. For example, in /items?id=###, the query parameter is id.
16
 *
17
 * - header: Custom headers that are expected as part of the request. Note that RFC7230 states header names are case
18
 * insensitive.
19
 *
20
 * - cookie: - Used to pass a specific cookie value to the API.
21
 *
22
 *
23
 * The rules for serialization of the parameter are specified in one of two ways.
24
 * For simpler scenarios, a "schema" and "style" can describe the structure and syntax of the parameter.
25
 *
26
 * For more complex scenarios, the "content" property can define the media type and schema of the parameter.
27
 * A parameter MUST contain either a "schema" property, or a "content" property, but not both
28
 * When "example" or "examples" are provided in conjunction with the "schema" object, the "example" MUST
29
 * follow the prescribed serialization strategy for the parameter.
30
 *
31
 * @see https://swagger.io/specification/#parameterObject
32
 */
33
class Parameter extends AbstractParameter
34
{
35
    const IN_PATH   = 'path';
36
    const IN_QUERY  = 'query';
37
    const IN_HEADER = 'header';
38
    const IN_COOKIE = 'cookie';
39
40
    /**
41
     * REQUIRED. The name of the parameter. Parameter names are case sensitive.
42
     *
43
     * - If in is "path", the name field MUST correspond to the associated path segment from the path field in the Paths
44
     * Object. See Path Templating for further information.
45
     *
46
     * - If in is "header" and the name field is "Accept",
47
     * "Content-Type" or "Authorization", the parameter definition SHALL be ignored.
48
     *
49
     * - For all other cases, the name corresponds to the parameter name used by the in property.
50
     *
51
     * @see https://swagger.io/specification/#pathTemplating
52
     *
53
     *
54
     * @var string
55
     */
56
    public $name;
57
58
    /**
59
     * REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie".
60
     *
61
     *
62
     * @var string
63
     */
64
    public $in;
65
66
    /**
67
     * @param string      $name
68
     * @param string      $in
69
     * @param string|null $description
70
     * @param array       $additionalProperties
71
     */
72 6
    public function __construct(string $name, string $in, string $description = null, array $additionalProperties = [])
73
    {
74 6
        parent::__construct($additionalProperties);
75 6
        $this->name        = $name;
76 6
        $this->in          = $in;
77 6
        $this->description = $description;
78 6
    }
79
}
80