Passed
Pull Request — master (#16)
by Woody
02:09
created

Parameter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 8
eloc 27
dl 0
loc 97
ccs 20
cts 28
cp 0.7143
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 7 1
A hasSchema() 0 3 1
A unserialize() 0 7 1
A __construct() 0 6 1
A getSchema() 0 3 1
A getName() 0 3 1
A isRequired() 0 3 1
A getLocation() 0 3 1
1
<?php
2
namespace ElevenLabs\Api\Definition;
3
4
class Parameter implements \Serializable
5
{
6
    const LOCATIONS = ['path', 'header', 'query', 'body', 'formData'];
7
    const BODY_LOCATIONS = ['formData', 'body'];
8
    const BODY_LOCATIONS_TYPES = ['formData' => 'application/x-www-form-urlencoded', 'body'  => 'application/json'];
9
10
    /**
11
     * Location of the parameter in the request
12
     *
13
     * @var string
14
     */
15
    private $location;
16
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * Indicate if the parameter should be present
24
     *
25
     * @var bool
26
     */
27
    private $required;
28
29
    /**
30
     * A JSON Schema object
31
     *
32
     * @var \stdClass
33
     */
34
    private $schema;
35
36 1
    public function __construct($location, $name, $required, \stdClass $schema = null)
37
    {
38 1
        $this->location = $location;
39 1
        $this->name = $name;
40 1
        $this->required = $required;
41 1
        $this->schema = $schema;
42 1
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getLocation()
48
    {
49
        return $this->location;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getName()
56
    {
57
        return $this->name;
58
    }
59
60
    /**
61
     * @return boolean
62
     */
63
    public function isRequired()
64
    {
65
        return $this->required;
66
    }
67
68
    /**
69
     * @return \stdClass
70
     */
71
    public function getSchema()
72
    {
73
        return $this->schema;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79 1
    public function hasSchema()
80
    {
81 1
        return $this->schema !== null;
82
    }
83
84 1
    public function serialize()
85
    {
86 1
        return serialize([
87 1
            'location' => $this->location,
88 1
            'name' => $this->name,
89 1
            'required' => $this->required,
90 1
            'schema' => $this->schema
91
        ]);
92
    }
93
94 1
    public function unserialize($serialized)
95
    {
96 1
        $data = unserialize($serialized);
97 1
        $this->location = $data['location'];
98 1
        $this->name = $data['name'];
99 1
        $this->required  = $data['required'];
100 1
        $this->schema  = $data['schema'];
101 1
    }
102
}
103