Relationships   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 6 2
A getRelationship() 0 14 3
1
<?php
2
/**
3
 * Relationships.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:JsonAPIClient!
9
 * @subpackage     Objects
10
 * @since          1.0.0
11
 *
12
 * @date           05.05.18
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\JsonAPIClient\Objects;
18
19
use CloudCreativity\Utils\Object\StandardObject;
20
21
use IPub\JsonAPIClient\Exceptions;
22
23
/**
24
 * Relationships
25
 *
26
 * @package        iPublikuj:JsonAPIClient!
27
 * @subpackage     Objects
28
 *
29
 * @author         Adam Kadlec <[email protected]>
30
 */
31
class Relationships extends StandardObject implements IRelationships
32
{
33
	/**
34
	 * {@inheritdoc}
35
	 */
36
	public function getAll() : \Traversable
37
	{
38
		foreach ($this->keys() as $key) {
39
			yield $key => $this->getRelationship($key);
40
		}
41
	}
42
43
	/**
44
	 * {@inheritdoc}
45
	 */
46
	public function getRelationship(string $key) : IRelationship
47
	{
48
		if (!$this->has($key)) {
49
			throw new Exceptions\RuntimeException(sprintf('Relationship member "%s" is not present.', $key));
50
		}
51
52
		$value = $this->{$key};
53
54
		if (!is_object($value)) {
55
			throw new Exceptions\RuntimeException(sprintf('Relationship member "%s" is not an object.', $key));
56
		}
57
58
		return new Relationship($value);
59
	}
60
}
61