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

Paths   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 90
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.12%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 13
c 5
b 0
f 0
lcom 1
cbo 5
dl 90
loc 90
ccs 32
cts 34
cp 0.9412
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 2
A parse() 14 14 3
A toArray() 5 5 1
A size() 3 3 1
A has() 3 3 1
A contains() 3 3 1
A get() 6 6 2
A add() 4 4 1
A remove() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
class Paths implements Arrayable {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
12
	
13
	use ExtensionPart;
14
	
15
	/** @var Map */
16
	private $paths;
17
18 9
	public function __construct($contents = null) {
19 9
		$this->parse($contents === null ? new Map() : $contents);
20 9
	}
21
	
22 9
	private function parse($contents) {
23 9
		$data = CollectionUtils::toMap($contents);
24
		
25
		// paths
26 9
		$this->paths = new Map();
27 9
		foreach ($data as $p => $path) {
28 5
			if (!Text::create($p)->startsWith('x-')) {
29 5
				$this->paths->set($p, new Path($p, $path));
30 5
			}
31 9
		}
32
33
		// extensions
34 9
		$this->parseExtensions($data);
35 9
	}
36
	
37 6
	public function toArray() {
38 6
		$paths = clone $this->paths;
39 6
		$paths->setAll($this->getExtensions());
40 6
		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