Code Duplication    Length = 84-87 lines in 2 locations

src/collections/Responses.php 1 location

@@ 11-94 (lines=84) @@
8
use phootwork\lang\Arrayable;
9
use phootwork\lang\Text;
10
11
class Responses implements Arrayable {
12
	
13
	use ExtensionPart;
14
	
15
	/** @var Map */
16
	private $responses;
17
	
18
	public function __construct($contents = null) {
19
		$this->parse($contents === null ? new Map() : $contents);
20
	}
21
	
22
	private function parse($contents) {
23
		$data = CollectionUtils::toMap($contents);
24
25
		// responses
26
		$this->responses = new Map();
27
		foreach ($data as $r => $response) {
28
			if (!Text::create($r)->startsWith('x-')) {
29
				$this->responses->set($r, new Response($r, $response));
30
			}
31
		}
32
		
33
		// extensions
34
		$this->parseExtensions($data);
35
	}
36
	
37
	public function toArray() {
38
		$responses = clone $this->responses;
39
		$responses->setAll($this->getExtensions());
40
		return $responses->toArray();
41
	}
42
43
	public function size() {
44
		return $this->responses->size();
45
	}
46
47
	/**
48
	 * Returns whether the given response exists
49
	 * 
50
	 * @param string $code
51
	 * @return boolean
52
	 */
53
	public function has($code) {
54
		return $this->responses->has($code);
55
	}
56
	
57
	/**
58
	 * Returns whether the given response exists
59
	 * 
60
	 * @param Response $response
61
	 * @return boolean
62
	 */
63
	public function contains(Response $response) {
64
		return $this->responses->contains($response);
65
	}
66
	
67
	/**
68
	 * Returns the reponse info for the given code
69
	 * 
70
	 * @param string $code
71
	 * @return Response
72
	 */
73
	public function get($code) {
74
		return $this->responses->get($code);
75
	}
76
	
77
	/**
78
	 * Sets the response
79
	 * 
80
	 * @param Response $code
81
	 */
82
	public function add(Response $response) {
83
		$this->responses->set($response->getCode(), $response);
84
	}
85
	
86
	/**
87
	 * Removes the given repsonse
88
	 * 
89
	 * @param string $code
90
	 */
91
	public function remove($code) {
92
		$this->responses->remove($code);
93
	}
94
}
95

src/collections/Paths.php 1 location

@@ 11-97 (lines=87) @@
8
use phootwork\lang\Text;
9
use phootwork\collection\CollectionUtils;
10
11
class Paths implements Arrayable {
12
	
13
	use ExtensionPart;
14
	
15
	/** @var Map */
16
	private $paths;
17
18
	public function __construct($contents = null) {
19
		$this->parse($contents === null ? new Map() : $contents);
20
	}
21
	
22
	private function parse($contents) {
23
		$data = CollectionUtils::toMap($contents);
24
		
25
		// paths
26
		$this->paths = new Map();
27
		foreach ($data as $p => $path) {
28
			if (!Text::create($p)->startsWith('x-')) {
29
				$this->paths->set($p, new Path($p, $path));
30
			}
31
		}
32
33
		// extensions
34
		$this->parseExtensions($data);
35
	}
36
	
37
	public function toArray() {
38
		$paths = clone $this->paths;
39
		$paths->setAll($this->getExtensions());
40
		return $paths->toArray();
41
	}
42
	
43
	public function size() {
44
		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
	public function has($path) {
54
		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
	public function contains(Path $path) {
64
		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
	public function get($path) {
74
		return $this->paths->get($path);
75
	}
76
	
77
	/**
78
	 * Sets the path
79
	 * 
80
	 * @param Path $path
81
	 * @return $this
82
	 */
83
	public function add(Path $path) {
84
		$this->paths->set($path->getPath(), $path);
85
		return $this;
86
	}
87
	
88
	/**
89
	 * Removes the given path
90
	 * 
91
	 * @param string $path
92
	 */
93
	public function remove($path) {
94
		$this->paths->remove($path);
95
		return $this;
96
	}
97
}
98