Document   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 6
dl 0
loc 94
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 18 5
A getResource() 0 10 2
A getResources() 0 10 2
A getRelationship() 0 4 1
A getIncluded() 0 12 3
A getErrors() 0 12 3
1
<?php
2
/**
3
 * Document.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
use CloudCreativity\Utils\Object\StandardObjectInterface;
21
22
use Neomerx\JsonApi\Exceptions\ErrorCollection;
23
24
use IPub\JsonAPIClient\Exceptions;
25
26
/**
27
 * Response document
28
 *
29
 * @package        iPublikuj:JsonAPIClient!
30
 * @subpackage     Objects
31
 *
32
 * @author         Adam Kadlec <[email protected]>
33
 */
34
class Document extends StandardObject implements IDocument
35
{
36
	use TMetaMember;
37
38
	/**
39
	 * {@inheritdoc}
40
	 */
41
	public function getData()
42
	{
43
		if (!$this->has(self::DATA)) {
44
			throw new Exceptions\RuntimeException('Data member is not present.');
45
		}
46
47
		$data = $this->get(self::DATA);
48
49
		if (is_array($data) || is_null($data)) {
50
			return $data;
51
		}
52
53
		if (!$data instanceof StandardObjectInterface) {
0 ignored issues
show
Bug introduced by
The class CloudCreativity\Utils\Ob...StandardObjectInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
54
			throw new Exceptions\RuntimeException('Data member is not an object or null.');
55
		}
56
57
		return $data;
58
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63
	public function getResource() : IResourceObject
64
	{
65
		$data = $this->{self::DATA};
66
67
		if (!is_object($data)) {
68
			throw new Exceptions\RuntimeException('Data member is not an object.');
69
		}
70
71
		return new ResourceObject($data);
72
	}
73
74
	/**
75
	 * {@inheritdoc}
76
	 */
77
	public function getResources() : IResourceObjectCollection
78
	{
79
		$data = $this->get(self::DATA);
80
81
		if (!is_array($data)) {
82
			throw new Exceptions\RuntimeException('Data member is not an array.');
83
		}
84
85
		return ResourceObjectCollection::create($data);
86
	}
87
88
	/**
89
	 * {@inheritdoc}
90
	 */
91
	public function getRelationship() : IRelationship
92
	{
93
		return new Relationship($this->proxy);
94
	}
95
96
	/**
97
	 * {@inheritdoc}
98
	 */
99
	public function getIncluded() : IResourceObjectCollection
100
	{
101
		if (!$this->has(self::INCLUDED)) {
102
			return NULL;
103
		}
104
105
		if (!is_array($data = $this->{self::INCLUDED})) {
106
			throw new Exceptions\RuntimeException('Included member is not an array.');
107
		}
108
109
		return ResourceObjectCollection::create($data);
110
	}
111
112
	/**
113
	 * {@inheritdoc}
114
	 */
115
	public function getErrors() : ?ErrorCollection
116
	{
117
		if (!$this->has(self::ERRORS)) {
118
			return NULL;
119
		}
120
121
		if (!is_array($data = $this->{self::ERRORS})) {
122
			throw new Exceptions\RuntimeException('Errors member is not an array.');
123
		}
124
125
		return Error::createMany($data);
126
	}
127
}
128