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\Schema; |
||
5 | use phootwork\collection\CollectionUtils; |
||
6 | use phootwork\lang\Arrayable; |
||
7 | use phootwork\collection\Map; |
||
8 | |||
9 | View Code Duplication | class Definitions implements Arrayable { |
|
0 ignored issues
–
show
|
|||
10 | |||
11 | /** @var Map */ |
||
12 | private $definitions; |
||
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 | $this->definitions = new Map(); |
||
22 | foreach ($data as $name => $prop) { |
||
23 | $this->definitions->set($name, new Schema($prop)); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | public function toArray() { |
||
28 | return $this->definitions->toArray(); |
||
29 | } |
||
30 | |||
31 | public function size() { |
||
32 | return $this->definitions->size(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Returns the schema for the given field |
||
37 | * |
||
38 | * @param string $name |
||
39 | * @return Schema |
||
40 | */ |
||
41 | public function get($name) { |
||
42 | return $this->definitions->get($name); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Sets the field |
||
47 | * |
||
48 | * @param string name |
||
49 | * @param Schema $schame |
||
50 | */ |
||
51 | public function set($name, Schema $schema) { |
||
52 | $this->definitions->set($name, $schema); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Removes the given field |
||
57 | * |
||
58 | * @param string $name |
||
59 | */ |
||
60 | public function remove($name) { |
||
61 | $this->definitions->remove($name); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Returns definitions has a schema with the given name |
||
66 | * |
||
67 | * @param string $name |
||
68 | * @return boolean |
||
69 | */ |
||
70 | public function has($name) { |
||
71 | return $this->definitions->has($name); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Returns whether the given schema exists |
||
76 | * |
||
77 | * @param Schema $schema |
||
78 | * @return boolean |
||
79 | */ |
||
80 | public function contains(Schema $schema) { |
||
81 | return $this->definitions->contains($schema); |
||
82 | } |
||
83 | } |
||
84 |
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.