AtMemberManager::addAtMember()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
namespace alsvanzelf\jsonapi\helpers;
4
5
use alsvanzelf\jsonapi\helpers\Converter;
6
use alsvanzelf\jsonapi\helpers\Validator;
7
8
trait AtMemberManager {
9
	/** @var array */
10
	protected $atMembers = [];
11
	
12
	/**
13
	 * human api
14
	 */
15
	
16
	/**
17
	 * spec api
18
	 */
19
	
20
	/**
21
	 * @param string $key
22
	 * @param mixed  $value
23
	 */
24 12
	public function addAtMember($key, $value) {
25 12
		if (strpos($key, '@') === 0) {
26 2
			$key = substr($key, 1);
27
		}
28
		
29 12
		Validator::checkMemberName($key);
30
		
31 11
		if (is_object($value)) {
32 1
			$value = Converter::objectToArray($value);
33
		}
34
		
35 11
		$this->atMembers['@'.$key] = $value;
36
	}
37
	
38
	/**
39
	 * internal api
40
	 */
41
	
42
	/**
43
	 * @internal
44
	 * 
45
	 * @return boolean
46
	 */
47 184
	public function hasAtMembers() {
48 184
		return ($this->atMembers !== []);
49
	}
50
	
51
	/**
52
	 * @internal
53
	 * 
54
	 * @return array
55
	 */
56 5
	public function getAtMembers() {
57 5
		return $this->atMembers;
58
	}
59
}
60