Completed
Pull Request — master (#3)
by Guilh
02:22
created

Definitions   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 69.23%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 17
c 6
b 1
f 0
lcom 1
cbo 3
dl 0
loc 116
ccs 27
cts 39
cp 0.6923
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A parse() 0 9 2
A toArray() 0 4 1
A size() 0 4 1
A get() 0 8 2
A set() 0 4 1
A remove() 0 4 1
A has() 0 4 1
A contains() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
1
<?php
2
3
namespace gossi\swagger\collections;
4
5
use gossi\swagger\Schema;
6
use phootwork\collection\CollectionUtils;
7
use phootwork\lang\Arrayable;
8
use phootwork\collection\Map;
9
10
class Definitions implements Arrayable, \Iterator
11
{
12
    /** @var Map */
13
    private $definitions;
14
15 12
    public function __construct($contents = [])
16
    {
17 12
        $this->parse($contents === null ? [] : $contents);
18 12
    }
19
20 12
    private function parse($contents)
21
    {
22 12
        $data = CollectionUtils::toMap($contents);
23
24 12
        $this->definitions = new Map();
25 12
        foreach ($data as $name => $prop) {
26 6
            $this->definitions->set($name, new Schema($prop));
27 12
        }
28 12
    }
29
30 7
    public function toArray()
31
    {
32 7
        return $this->definitions->toArray();
33
    }
34
35 1
    public function size()
36
    {
37 1
        return $this->definitions->size();
38
    }
39
40
    /**
41
     * Returns the schema for the given field.
42
     * 
43
     * @param string $name
44
     *
45
     * @return Schema
46
     */
47 1
    public function get($name)
48
    {
49 1
        if (!$this->definitions->has($name)) {
50
            $this->definitions->set($name, new Schema());
51
        }
52
53 1
        return $this->definitions->get($name);
54
    }
55
56
    /**
57
     * Sets the field.
58
     * 
59
     * @param string name
60
     * @param Schema $schame
0 ignored issues
show
Bug introduced by
There is no parameter named $schame. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
61
     */
62 1
    public function set($name, Schema $schema)
63
    {
64 1
        $this->definitions->set($name, $schema);
65 1
    }
66
67
    /**
68
     * Removes the given field.
69
     * 
70
     * @param string $name
71
     */
72 1
    public function remove($name)
73
    {
74 1
        $this->definitions->remove($name);
75 1
    }
76
77
    /**
78
     * Returns definitions has a schema with the given name.
79
     * 
80
     * @param string $name
81
     *
82
     * @return bool
83
     */
84 1
    public function has($name)
85
    {
86 1
        return $this->definitions->has($name);
87
    }
88
89
    /**
90
     * Returns whether the given schema exists.
91
     * 
92
     * @param Schema $schema
93
     *
94
     * @return bool
95
     */
96 1
    public function contains(Schema $schema)
97
    {
98 1
        return $this->definitions->contains($schema);
99
    }
100
101
    public function current()
102
    {
103
        return $this->definitions->current();
104
    }
105
106
    public function key()
107
    {
108
        return $this->definitions->key();
109
    }
110
111
    public function next()
112
    {
113
        return $this->definitions->next();
114
    }
115
116
    public function rewind()
117
    {
118
        return $this->definitions->rewind();
119
    }
120
121
    public function valid()
122
    {
123
        return $this->definitions->valid();
124
    }
125
}
126