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

MagicSetters   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 4 1
A __unset() 0 4 1
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
}