LinksManager::appendLinkObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
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 {
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
21
	 * @param string $href
22
	 * @param array  $meta optional, if given a LinkObject is added, otherwise a link string is added
23
	 */
24 28
	public function addLink($key, $href, array $meta=[]) {
25 28
		$this->ensureLinksObject();
26 28
		$this->links->add($key, $href, $meta);
27
	}
28
	
29
	/**
30
	 * append a link to a key with an array of links
31
	 * 
32
	 * @deprecated array links are not supported anymore {@see ->addLink()}
33
	 * 
34
	 * @param string $key
35
	 * @param string $href
36
	 * @param array  $meta optional, if given a LinkObject is added, otherwise a link string is added
37
	 */
38 4
	public function appendLink($key, $href, array $meta=[]) {
39 4
		$this->ensureLinksObject();
40 4
		$this->links->append($key, $href, $meta);
0 ignored issues
show
Deprecated Code introduced by
The function alsvanzelf\jsonapi\objects\LinksObject::append() has been deprecated: array links are not supported anymore {@see ->add()} ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

40
		/** @scrutinizer ignore-deprecated */ $this->links->append($key, $href, $meta);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
41
	}
42
	
43
	/**
44
	 * spec api
45
	 */
46
	
47
	/**
48
	 * set a key containing a LinkObject
49
	 * 
50
	 * @param string     $key
51
	 * @param LinkObject $linkObject
52
	 */
53 14
	public function addLinkObject($key, LinkObject $linkObject) {
54 14
		$this->ensureLinksObject();
55 14
		$this->links->addLinkObject($key, $linkObject);
56
	}
57
	
58
	/**
59
	 * set a key containing a LinksArray
60
	 * 
61
	 * @deprecated array links are not supported anymore {@see ->addLinkObject()}
62
	 * 
63
	 * @param string     $key
64
	 * @param LinksArray $linksArray
65
	 */
66 2
	public function addLinksArray($key, LinksArray $linksArray) {
67 2
		$this->ensureLinksObject();
68 2
		$this->links->addLinksArray($key, $linksArray);
0 ignored issues
show
Deprecated Code introduced by
The function alsvanzelf\jsonapi\objec...Object::addLinksArray() has been deprecated: array links are not supported anymore {@see ->addLinkObject()} ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
		/** @scrutinizer ignore-deprecated */ $this->links->addLinksArray($key, $linksArray);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
69
	}
70
	
71
	/**
72
	 * append a LinkObject to a key with a LinksArray
73
	 * 
74
	 * @deprecated array links are not supported anymore {@see ->addLinkObject()}
75
	 * 
76
	 * @param string     $key
77
	 * @param LinkObject $linkObject
78
	 */
79 1
	public function appendLinkObject($key, LinkObject $linkObject) {
80 1
		$this->ensureLinksObject();
81 1
		$this->links->appendLinkObject($key, $linkObject);
0 ignored issues
show
Deprecated Code introduced by
The function alsvanzelf\jsonapi\objec...ect::appendLinkObject() has been deprecated: array links are not supported anymore {@see ->addLinkObject()} ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

81
		/** @scrutinizer ignore-deprecated */ $this->links->appendLinkObject($key, $linkObject);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
82
	}
83
	
84
	/**
85
	 * set a LinksObject containing all links
86
	 * 
87
	 * @param LinksObject $linksObject
88
	 */
89 52
	public function setLinksObject(LinksObject $linksObject) {
90 52
		$this->links = $linksObject;
91
	}
92
	
93
	/**
94
	 * internal api
95
	 */
96
	
97
	/**
98
	 * @internal
99
	 */
100 46
	private function ensureLinksObject() {
101 46
		if ($this->links === null) {
102 46
			$this->setLinksObject(new LinksObject());
103
		}
104
	}
105
}
106