Completed
Push — master ( 10a146...62fa38 )
by Thomas
8s
created

Paths::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.2559
1
<?php
2
namespace gossi\swagger\collections;
3
4
use gossi\swagger\parts\ExtensionPart;
5
use gossi\swagger\Path;
6
use phootwork\collection\Map;
7
use phootwork\lang\Arrayable;
8
use phootwork\lang\Text;
9
use phootwork\collection\CollectionUtils;
10
11
class Paths implements Arrayable, \Iterator {
12
	
13
	use ExtensionPart;
14
	
15
	/** @var Map */
16
	private $paths;
17
18 10
	public function __construct($contents = []) {
19 10
		$this->parse($contents === null ? [] : $contents);
20 10
	}
21
	
22 10
	private function parse($contents) {
23 10
		$data = CollectionUtils::toMap($contents);
24
		
25
		// paths
26 10
		$this->paths = new Map();
27 10
		foreach ($data as $p => $path) {
28 6
			if (!Text::create($p)->startsWith('x-')) {
29 6
				$this->paths->set($p, new Path($p, $path));
30 6
			}
31 10
		}
32
33
		// extensions
34 10
		$this->parseExtensions($data);
35 10
	}
36
	
37 7
	public function toArray() {
38 7
		$paths = clone $this->paths;
39
// 		$paths->setAll($this->getExtensions());
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40 7
		return $paths->toArray();
41
	}
42
	
43 1
	public function size() {
44 1
		return $this->paths->size();
45
	}
46
	
47
	/**
48
	 * Returns whether a path with the given name exists
49
	 * 
50
	 * @param string $path
51
	 * @return boolean
52
	 */
53 1
	public function has($path) {
54 1
		return $this->paths->has($path);
55
	}
56
	
57
	/**
58
	 * Returns whether the given path exists
59
	 * 
60
	 * @param Path $path
61
	 * @return boolean
62
	 */
63 1
	public function contains(Path $path) {
64 1
		return $this->paths->contains($path);
65
	}
66
	
67
	/**
68
	 * Returns the path info for the given path
69
	 * 
70
	 * @param string $path
71
	 * @return Path
72
	 */
73 2
	public function get($path) {
74 2
		if (!$this->paths->has($path)) {
75
			$this->paths->set($path, new Path($path));
76
		}
77 2
		return $this->paths->get($path);
78
	}
79
	
80
	/**
81
	 * Sets the path
82
	 * 
83
	 * @param Path $path
84
	 * @return $this
85
	 */
86 1
	public function add(Path $path) {
87 1
		$this->paths->set($path->getPath(), $path);
88 1
		return $this;
89
	}
90
	
91
	/**
92
	 * Removes the given path
93
	 * 
94
	 * @param string $path
95
	 */
96 1
	public function remove($path) {
97 1
		$this->paths->remove($path);
98 1
		return $this;
99
	}
100
	
101
	public function current() {
102
		return $this->paths->current();
103
	}
104
	
105
	public function key() {
106
		return $this->paths->key();
107
	}
108
	
109
	public function next() {
110
		return $this->paths->next();
111
	}
112
	
113
	public function rewind() {
114
		return $this->paths->rewind();
115
	}
116
	
117
	public function valid() {
118
		return $this->paths->valid();
119
	}
120
}
121