Completed
Push — master ( 91e761...756f60 )
by Thomas
02:42
created

Definitions   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.1%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 78
ccs 27
cts 29
cp 0.931
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A parse() 0 8 2
A toArray() 0 3 1
A size() 0 3 1
A get() 0 6 2
A set() 0 3 1
A remove() 0 3 1
A has() 0 3 1
A contains() 0 3 1
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
class Definitions implements Arrayable {
10
	
11
	/** @var Map */
12
	private $definitions;
13
14 11
	public function __construct($contents = null) {
15 11
		$this->parse($contents === null ? new Map() : $contents);
16 11
	}
17
	
18 11
	private function parse($contents) {
19 11
		$data = CollectionUtils::toMap($contents);
20
21 11
		$this->definitions = new Map();
22 11
		foreach ($data as $name => $prop) {
23 5
			$this->definitions->set($name, new Schema($prop));
24 11
		}
25 11
	}
26
27 6
	public function toArray() {
28 6
		return $this->definitions->toArray();
29
	}
30
	
31 1
	public function size() {
32 1
		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 1
	public function get($name) {
42 1
		if (!$this->definitions->has($name)) {
43
			$this->definitions->set($name, new Schema());
44
		}
45 1
		return $this->definitions->get($name);
46
	}
47
	
48
	/**
49
	 * Sets the field
50
	 * 
51
	 * @param string name
52
	 * @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...
53
	 */
54 1
	public function set($name, Schema $schema) {
55 1
		$this->definitions->set($name, $schema);
56 1
	}
57
	
58
	/**
59
	 * Removes the given field
60
	 * 
61
	 * @param string $name
62
	 */
63 1
	public function remove($name) {
64 1
		$this->definitions->remove($name);
65 1
	}
66
	
67
	/**
68
	 * Returns definitions has a schema with the given name
69
	 * 
70
	 * @param string $name
71
	 * @return boolean
72
	 */
73 1
	public function has($name) {
74 1
		return $this->definitions->has($name);
75
	}
76
	
77
	/**
78
	 * Returns whether the given schema exists
79
	 * 
80
	 * @param Schema $schema
81
	 * @return boolean
82
	 */
83 1
	public function contains(Schema $schema) {
84 1
		return $this->definitions->contains($schema);
85
	}
86
}
87