Completed
Push — master ( 425846...6cb170 )
by Adam
07:36
created

Resource   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 137
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setParent() 0 4 1
A getParent() 0 4 1
A setChildren() 0 10 3
A addChild() 0 6 2
A getChildren() 0 4 1
A getResourceId() 0 4 1
A setName() 0 4 1
A getName() 0 4 1
A setComment() 0 4 1
A getComment() 0 4 1
A __toString() 0 4 1
1
<?php
2
/**
3
 * IResource.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
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
class Resource implements IResource
22
{
23
	/**
24
	 * Implement nette smart magic
25
	 */
26
	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
		$this->id = $id;
56
57
		$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
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63
	public function setParent(IResource $parent = NULL)
64
	{
65
		$this->parent = $parent;
66
	}
67
68
	/**
69
	 * {@inheritdoc}
70
	 */
71
	public function getParent()
72
	{
73
		return $this->parent;
74
	}
75
76
	/**
77
	 * {@inheritdoc}
78
	 */
79
	public function setChildren(array $resources)
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)
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()
104
	{
105
		return $this->children;
106
	}
107
108
	/**
109
	 * {@inheritdoc}
110
	 */
111
	public function getResourceId() : string
112
	{
113
		return $this->id;
114
	}
115
116
	/**
117
	 * {@inheritdoc}
118
	 */
119
	public function setName(string $name)
120
	{
121
		$this->name = $name;
122
	}
123
124
	/**
125
	 * {@inheritdoc}
126
	 */
127
	public function getName()
128
	{
129
		return $this->name;
130
	}
131
132
	/**
133
	 * {@inheritdoc}
134
	 */
135
	public function setComment(string $comment)
136
	{
137
		$this->comment = $comment;
138
	}
139
140
	/**
141
	 * {@inheritdoc}
142
	 */
143
	public function getComment()
144
	{
145
		return $this->comment;
146
	}
147
148
	/**
149
	 * Convert resource object to string
150
	 *
151
	 * @return string
152
	 */
153
	public function __toString()
154
	{
155
		return $this->id;
156
	}
157
}
158