Test Failed
Pull Request — main (#64)
by Lode
08:15
created

LinksManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 91
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addLink() 0 4 1
A appendLink() 0 4 1
A addLinkObject() 0 4 1
A addLinksArray() 0 4 1
A appendLinkObject() 0 4 1
A setLinksObject() 0 3 1
A ensureLinksObject() 0 5 2
1
<?php
2
3
namespace alsvanzelf\jsonapi\helpers;
4
5
use alsvanzelf\jsonapi\objects\LinkObject;
6
use alsvanzelf\jsonapi\objects\LinksArray;
7
use alsvanzelf\jsonapi\objects\LinksObject;
8
9
trait LinksManager {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait LinksManager
Loading history...
10
	/** @var LinksObject */
11
	protected $links;
12
	
13
	/**
14
	 * human api
15
	 */
16
	
17
	/**
18
	 * set a key containing a link
19
	 * 
20
	 * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
21
	 * @param string $href
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
22
	 * @param array  $meta optional, if given a LinkObject is added, otherwise a link string is added
23
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
24
	public function addLink($key, $href, array $meta=[]) {
25
		$this->ensureLinksObject();
26
		$this->links->add($key, $href, $meta);
27
	}
28
	
29
	/**
30
	 * append a link to a key with an array of links
31
	 * 
32
	 * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
33
	 * @param string $href
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
34
	 * @param array  $meta optional, if given a LinkObject is added, otherwise a link string is added
35
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
36
	public function appendLink($key, $href, array $meta=[]) {
37
		$this->ensureLinksObject();
38
		$this->links->append($key, $href, $meta);
39
	}
40
	
41
	/**
42
	 * spec api
43
	 */
44
	
45
	/**
46
	 * set a key containing a LinkObject
47
	 * 
48
	 * @param string     $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
49
	 * @param LinkObject $linkObject
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
50
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
51
	public function addLinkObject($key, LinkObject $linkObject) {
52
		$this->ensureLinksObject();
53
		$this->links->addLinkObject($key, $linkObject);
54
	}
55
	
56
	/**
57
	 * set a key containing a LinksArray
58
	 * 
59
	 * @param string     $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
60
	 * @param LinksArray $linksArray
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
61
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
62
	public function addLinksArray($key, LinksArray $linksArray) {
63
		$this->ensureLinksObject();
64
		$this->links->addLinksArray($key, $linksArray);
65
	}
66
	
67
	/**
68
	 * append a LinkObject to a key with a LinksArray
69
	 * 
70
	 * @param string     $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
71
	 * @param LinkObject $linkObject
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
72
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
73
	public function appendLinkObject($key, LinkObject $linkObject) {
74
		$this->ensureLinksObject();
75
		$this->links->appendLinkObject($key, $linkObject);
76
	}
77
	
78
	/**
79
	 * set a LinksObject containing all links
80
	 * 
81
	 * @param LinksObject $linksObject
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
82
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
83
	public function setLinksObject(LinksObject $linksObject) {
84
		$this->links = $linksObject;
85
	}
86
	
87
	/**
88
	 * internal api
89
	 */
90
	
91
	/**
92
	 * @internal
93
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
94
	private function ensureLinksObject() {
95
		if ($this->links === null) {
96
			$this->setLinksObject(new LinksObject());
97
		}
98
	}
99
}
100