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

LinkObject::toArray()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
3
namespace alsvanzelf\jsonapi\objects;
4
5
use alsvanzelf\jsonapi\helpers\AtMemberManager;
6
use alsvanzelf\jsonapi\interfaces\ObjectInterface;
7
use alsvanzelf\jsonapi\objects\MetaObject;
8
9
class LinkObject implements ObjectInterface {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class LinkObject
Loading history...
10
	use AtMemberManager;
11
	
12
	/** @var string */
13
	protected $href;
14
	/** @var MetaObject */
15
	protected $meta;
16
	
17
	/**
18
	 * @param string $href
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
19
	 * @param array  $meta optional
20
	 */
21
	public function __construct($href=null, array $meta=[]) {
22
		if ($href !== null) {
23
			$this->setHref($href);
24
		}
25
		if ($meta !== []) {
26
			$this->setMetaObject(MetaObject::fromArray($meta));
27
		}
28
	}
29
	
30
	/**
31
	 * human api
32
	 */
33
	
34
	/**
35
	 * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
36
	 * @param mixed  $value
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
37
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
38
	public function addMeta($key, $value) {
39
		if ($this->meta === null) {
40
			$this->setMetaObject(new MetaObject());
41
		}
42
		
43
		$this->meta->add($key, $value);
44
	}
45
	
46
	/**
47
	 * spec api
48
	 */
49
	
50
	/**
51
	 * @param string $href
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
53
	public function setHref($href) {
54
		$this->href = $href;
55
	}
56
	
57
	/**
58
	 * @param MetaObject $metaObject
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
59
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
60
	public function setMetaObject(MetaObject $metaObject) {
61
		$this->meta = $metaObject;
62
	}
63
	
64
	/**
65
	 * ObjectInterface
66
	 */
67
	
68
	/**
69
	 * @inheritDoc
70
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
71 View Code Duplication
	public function isEmpty() {
0 ignored issues
show
Duplication introduced by
This method 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...
72
		if ($this->href !== null) {
73
			return false;
74
		}
75
		if ($this->meta !== null && $this->meta->isEmpty() === false) {
76
			return false;
77
		}
78
		if ($this->hasAtMembers()) {
79
			return false;
80
		}
81
		
82
		return true;
83
	}
84
	
85
	/**
86
	 * @inheritDoc
87
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
88 View Code Duplication
	public function toArray() {
0 ignored issues
show
Duplication introduced by
This method 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...
89
		$array = $this->getAtMembers();
90
		
91
		$array['href'] = $this->href;
92
		
93
		if ($this->meta !== null && $this->meta->isEmpty() === false) {
94
			$array['meta'] = $this->meta->toArray();
95
		}
96
		
97
		return $array;
98
	}
99
}
100