HasAttributes::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace ElegantMedia\PHPToolkit\Types;
4
5
trait HasAttributes
6
{
7
	protected $attributes = [];
8
9
	public function __set($name, $value): void
10
	{
11
		$this->attributes[$name] = $value;
12
	}
13
14
	public function __get($name)
15
	{
16
		if (!array_key_exists($name, $this->attributes)) {
17
			return null;
18
		}
19
20
		return $this->attributes[$name];
21
	}
22
23
	public function __isset($name): bool
24
	{
25
		return isset($this->attributes[$name]);
26
	}
27
28
	public function __unset($name)
29
	{
30
		unset($this->attributes[$name]);
31
	}
32
}
33