Completed
Branch master (a17b64)
by Rémi
15:50
created

MagicSetters::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Analogue\ORM;
4
5
/**
6
 * This trait assumes that the MagicGetters trait is used as well. 
7
 */
8
trait MagicSetters
9
{
10
    /**
11
     * Dynamically set attributes on the entity.
12
     *
13
     * @param  string $key
14
     * @param  mixed  $value
15
     * @return void
16
     */
17
    public function __set($key, $value)
18
    {
19
        $this->attributes[$key] = $value;
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
    }
21
22
    /**
23
     * Unset an attribute on the entity.
24
     *
25
     * @param  string $key
26
     * @return void
27
     */
28
    public function __unset($key)
29
    {
30
        unset($this->attributes[$key]);
31
    }
32
33
34
}