Completed
Push — master ( 89d255...f8b47e )
by Thomas
03:08
created

Paths::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
namespace gossi\swagger\collections;
3
4
use gossi\swagger\parts\ExtensionPart;
5
use gossi\swagger\Path;
6
use phootwork\collection\CollectionUtils;
7
use phootwork\collection\Map;
8
use phootwork\lang\Arrayable;
9
use phootwork\lang\Text;
10
use gossi\swagger\AbstractModel;
11
12
class Paths extends AbstractModel implements Arrayable, \Iterator {
13
14
	use ExtensionPart;
15
16
	/** @var Map */
17
	private $paths;
18
19 10
	public function __construct($contents = []) {
20 10
		$this->parse($contents === null ? [] : $contents);
21 10
	}
22
23 10
	private function parse($contents) {
24 10
		$data = CollectionUtils::toMap($contents);
25
26
		// paths
27 10
		$this->paths = new Map();
28 10
		foreach ($data as $p => $path) {
29 6
			if (!Text::create($p)->startsWith('x-')) {
30 6
				$this->paths->set($p, new Path($p, $path));
31 6
			}
32 10
		}
33
34
		// extensions
35 10
		$this->parseExtensions($data);
36 10
	}
37
38 8
	public function toArray() {
39
// 		$paths = clone $this->paths;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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
// 		$paths->setAll($this->getExtensions());
41
// 		return $paths->toArray();
42 8
		return $this->exportRecursiveArray($this->paths->toArray());
43
	}
44
45 1
	public function size() {
46 1
		return $this->paths->size();
47
	}
48
49
	/**
50
	 * Returns whether a path with the given name exists
51
	 *
52
	 * @param string $path
53
	 * @return bool
54
	 */
55 1
	public function has($path) {
56 1
		return $this->paths->has($path);
57
	}
58
59
	/**
60
	 * Returns whether the given path exists
61
	 *
62
	 * @param Path $path
63
	 * @return bool
64
	 */
65 1
	public function contains(Path $path) {
66 1
		return $this->paths->contains($path);
67
	}
68
69
	/**
70
	 * Returns the path info for the given path
71
	 *
72
	 * @param string $path
73
	 * @return Path
74
	 */
75 2
	public function get($path) {
76 2
		if (!$this->paths->has($path)) {
77
			$this->paths->set($path, new Path($path));
78
		}
79 2
		return $this->paths->get($path);
80
	}
81
82
	/**
83
	 * Sets the path
84
	 *
85
	 * @param Path $path
86
	 * @return $this
87
	 */
88 1
	public function add(Path $path) {
89 1
		$this->paths->set($path->getPath(), $path);
90 1
		return $this;
91
	}
92
93
	/**
94
	 * Removes the given path
95
	 *
96
	 * @param string $path
97
	 */
98 1
	public function remove($path) {
99 1
		$this->paths->remove($path);
100 1
		return $this;
101
	}
102
103
	public function current() {
104
		return $this->paths->current();
105
	}
106
107
	public function key() {
108
		return $this->paths->key();
109
	}
110
111
	public function next() {
112
		return $this->paths->next();
113
	}
114
115
	public function rewind() {
116
		return $this->paths->rewind();
117
	}
118
119
	public function valid() {
120
		return $this->paths->valid();
121
	}
122
}
123