GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — place-services ( fedba7 )
by Eric
03:31
created

PlaceAutocompleteRequest::removeComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Place\Autocomplete\Request;
13
14
/**
15
 * @author GeLo <[email protected]>
16
 */
17
class PlaceAutocompleteRequest extends AbstractPlaceAutocompleteRequest
18
{
19
    /**
20
     * @var string[]
21
     */
22
    private $types = [];
23
24
    /**
25
     * @var string[]
26
     */
27
    private $components = [];
28
29
    /**
30
     * @return bool
31
     */
32
    public function hasTypes()
33
    {
34
        return !empty($this->types);
35
    }
36
37
    /**
38
     * @return string[]
39
     */
40
    public function getTypes()
41
    {
42
        return $this->types;
43
    }
44
45
    /**
46
     * @param string[] $types
47
     */
48
    public function setTypes(array $types)
49
    {
50
        $this->types = [];
51
        $this->addTypes($types);
52
    }
53
54
    /**
55
     * @param string[] $types
56
     */
57
    public function addTypes(array $types)
58
    {
59
        foreach ($types as $type) {
60
            $this->addType($type);
61
        }
62
    }
63
64
    /**
65
     * @param string $type
66
     *
67
     * @return bool
68
     */
69
    public function hasType($type)
70
    {
71
        return in_array($type, $this->types, true);
72
    }
73
74
    /**
75
     * @param string $type
76
     */
77
    public function addType($type)
78
    {
79
        if (!$this->hasType($type)) {
80
            $this->types[] = $type;
81
        }
82
    }
83
84
    /**
85
     * @param string $type
86
     */
87
    public function removeType($type)
88
    {
89
        unset($this->types[array_search($type, $this->types, true)]);
90
        $this->types = array_values($this->types);
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    public function hasComponents()
97
    {
98
        return !empty($this->components);
99
    }
100
101
    /**
102
     * @return string[]
103
     */
104
    public function getComponents()
105
    {
106
        return $this->components;
107
    }
108
109
    /**
110
     * @param string[] $components
111
     */
112
    public function setComponents(array $components)
113
    {
114
        $this->components = [];
115
        $this->addComponents($components);
116
    }
117
118
    /**
119
     * @param string[] $components
120
     */
121
    public function addComponents(array $components)
122
    {
123
        foreach ($components as $type => $value) {
124
            $this->setComponent($type, $value);
125
        }
126
    }
127
128
    /**
129
     * @param string $type
130
     *
131
     * @return bool
132
     */
133
    public function hasComponent($type)
134
    {
135
        return isset($this->components[$type]);
136
    }
137
138
    /**
139
     * @param string $type
140
     *
141
     * @return string
142
     */
143
    public function getComponent($type)
144
    {
145
        return $this->hasComponent($type) ? $this->components[$type] : null;
146
    }
147
148
    /**
149
     * @param string $type
150
     * @param string $value
151
     */
152
    public function setComponent($type, $value)
153
    {
154
        $this->components[$type] = $value;
155
    }
156
157
    /**
158
     * @param string $type
159
     */
160
    public function removeComponent($type)
161
    {
162
        unset($this->components[$type]);
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function buildContext()
169
    {
170
        return 'autocomplete';
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function buildQuery()
177
    {
178
        $query = parent::buildQuery();
179
180
        if ($this->hasTypes()) {
181
            $query['types'] = implode('|', $this->types);
182
        }
183
184 View Code Duplication
        if ($this->hasComponents()) {
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...
185
            $query['components'] = implode('|', array_map(function ($key, $value) {
186
                return $key.':'.$value;
187
            }, array_keys($this->components), array_values($this->components)));
188
        }
189
190
        return $query;
191
    }
192
}
193