These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace gossi\swagger\collections; |
||
3 | |||
4 | use gossi\swagger\Header; |
||
5 | use phootwork\collection\CollectionUtils; |
||
6 | use phootwork\collection\Map; |
||
7 | use phootwork\lang\Arrayable; |
||
8 | |||
9 | View Code Duplication | class Headers implements Arrayable { |
|
0 ignored issues
–
show
|
|||
10 | |||
11 | /** @var Map */ |
||
12 | private $headers; |
||
13 | |||
14 | public function __construct($contents = null) { |
||
15 | $this->parse($contents === null ? new Map() : $contents); |
||
16 | } |
||
17 | |||
18 | private function parse($contents) { |
||
19 | $data = CollectionUtils::toMap($contents); |
||
20 | |||
21 | // headers |
||
22 | $this->headers = new Map(); |
||
23 | foreach ($data as $h => $props) { |
||
24 | $this->headers->set($h, new Header($h, $props)); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | public function toArray() { |
||
29 | return $this->headers->toArray(); |
||
30 | } |
||
31 | |||
32 | public function size() { |
||
33 | return $this->headers->size(); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Returns whether a header with the given name exists |
||
38 | * |
||
39 | * @param string $header |
||
40 | * @return boolean |
||
41 | */ |
||
42 | public function has($header) { |
||
43 | return $this->headers->has($header); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Returns whether the given header exists |
||
48 | * |
||
49 | * @param Header $header |
||
50 | * @return boolean |
||
51 | */ |
||
52 | public function contains(Header $header) { |
||
53 | return $this->headers->contains($header); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Returns the header info for the given code |
||
58 | * |
||
59 | * @param string $header |
||
60 | * @return Header |
||
61 | */ |
||
62 | public function get($header) { |
||
63 | return $this->headers->get($header); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Sets the header |
||
68 | * |
||
69 | * @param Header $header |
||
70 | */ |
||
71 | public function set(Header $header) { |
||
72 | $this->headers->set($header->getCode(), $header); |
||
0 ignored issues
–
show
The method
getCode() does not seem to exist on object<gossi\swagger\Header> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Removes the given header |
||
77 | * |
||
78 | * @param string $header |
||
79 | */ |
||
80 | public function remove($header) { |
||
81 | $this->headers->remove($header); |
||
82 | } |
||
83 | |||
84 | } |
||
85 |
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.