Resource::setChildren()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * IResource.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Permissions!
9
 * @subpackage     Entities
10
 * @since          2.0.0
11
 *
12
 * @date           30.11.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Permissions\Entities;
18
19
use Nette;
20
21 1
class Resource implements IResource
22
{
23
	/**
24
	 * Implement nette smart magic
25
	 */
26 1
	use Nette\SmartObject;
27
28
	/**
29
	 * @var string
30
	 */
31
	protected $id;
32
33
	/**
34
	 * @var IResource|NULL
35
	 */
36
	protected $parent;
37
38
	/**
39
	 * @var IResource[]
40
	 */
41
	protected $children;
42
43
	/**
44
	 * @var string|NULL
45
	 */
46
	protected $name;
47
48
	/**
49
	 * @var string|NULL
50
	 */
51
	protected $comment;
52
53
	public function __construct(string $id)
54
	{
55 1
		$this->id = $id;
56
57 1
		$this->children = new \SplObjectStorage();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SplObjectStorage() of type object<SplObjectStorage> is incompatible with the declared type array<integer,object<IPu...ns\Entities\IResource>> of property $children.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58 1
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63
	public function setParent(IResource $parent = NULL) : void
64
	{
65
		$this->parent = $parent;
66
	}
67
68
	/**
69
	 * {@inheritdoc}
70
	 */
71
	public function getParent() : ?IResource
72
	{
73 1
		return $this->parent;
74
	}
75
76
	/**
77
	 * {@inheritdoc}
78
	 */
79
	public function setChildren(array $resources) : void
80
	{
81
		$this->children = new \SplObjectStorage();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SplObjectStorage() of type object<SplObjectStorage> is incompatible with the declared type array<integer,object<IPu...ns\Entities\IResource>> of property $children.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
83
		foreach ($resources as $child) {
84
			if ($child instanceof IResource) {
85
				$this->children->attach($child);
86
			}
87
		}
88
	}
89
90
	/**
91
	 * {@inheritdoc}
92
	 */
93
	public function addChild(IResource $resource) : void
94
	{
95
		if (!$this->children->contains($resource)) {
0 ignored issues
show
Bug introduced by
The method contains cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
			$this->children->attach($resource);
0 ignored issues
show
Bug introduced by
The method attach cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
97
		}
98
	}
99
100
	/**
101
	 * {@inheritdoc}
102
	 */
103
	public function getChildren() : array
104
	{
105
		$children = [];
106
107
		$this->children->rewind();
0 ignored issues
show
Bug introduced by
The method rewind cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
108
109
		while ($this->children->valid())
0 ignored issues
show
Bug introduced by
The method valid cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
110
		{
111
			$children[] = $this->children->current();
0 ignored issues
show
Bug introduced by
The method current cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
			$this->children->next();
0 ignored issues
show
Bug introduced by
The method next cannot be called on $this->children (of type array<integer,object<IPu...ns\Entities\IResource>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
113
		}
114
115
		return $children;
116
	}
117
118
	/**
119
	 * {@inheritdoc}
120
	 */
121
	public function getResourceId() : string
122
	{
123 1
		return $this->id;
124
	}
125
126
	/**
127
	 * {@inheritdoc}
128
	 */
129
	public function setName(string $name) : void
130
	{
131
		$this->name = $name;
132
	}
133
134
	/**
135
	 * {@inheritdoc}
136
	 */
137
	public function getName() : ?string
138
	{
139
		return $this->name;
140
	}
141
142
	/**
143
	 * {@inheritdoc}
144
	 */
145
	public function setComment(string $comment) : void
146
	{
147
		$this->comment = $comment;
148
	}
149
150
	/**
151
	 * {@inheritdoc}
152
	 */
153
	public function getComment() : ?string
154
	{
155
		return $this->comment;
156
	}
157
158
	/**
159
	 * Convert resource object to string
160
	 *
161
	 * @return string
162
	 */
163
	public function __toString()
164
	{
165 1
		return $this->id;
166
	}
167
}
168