Passed
Push — master ( 747cf5...5f46f3 )
by compolom
42s
created

Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace DrMVC\Orm;
4
5
/**
6
 * Class Entity
7
 * @package DrMVC\Orm
8
 *
9
 * @property int id
10
 * @method Entity getId(): int
11
 */
12
class Entity
13
{
14
    /**
15
     * Magic container
16
     *
17
     * @var array
18
     */
19
    private $_data = [];
20
21
    /**
22
     * Get all fields
23
     *
24
     * @return array
25
     */
26 2
    public function getData(): array
27
    {
28 2
        return $this->_data;
29
    }
30
31
    /**
32
     * @param string $name
33
     * @return mixed|null
34
     */
35 7
    public function __get(string $name)
36
    {
37 7
        return $this->_data[$name] ?? null;
38
    }
39
40
    /**
41
     * @param string $name
42
     * @param $value
43
     */
44 10
    public function __set(string $name, $value)//: void 7.1
45
    {
46 10
        $this->_data[$name] = $value;
47 10
    }
48
49
    /**
50
     * @param string $name
51
     * @return bool
52
     */
53 1
    public function __isset(string $name): bool
54
    {
55 1
        return isset($this->_data[$name]);
56
    }
57
58
    /**
59
     * @param string $name
60
     */
61 1
    public function __unset(string $name)//: void 7.1
62
    {
63 1
        unset($this->_data[$name]);
64 1
    }
65
66
    /**
67
     * Magic setters and getters
68
     *
69
     * @param $name
70
     * @param $arguments
71
     * @return bool|mixed|null
72
     */
73 4
    public function __call($name, $arguments)
74
    {
75 4
        $action = substr($name, 0, 3);
76 4
        $property = strtolower(substr($name, 3));
77
        switch ($action) {
78 4
            case 'get':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
79 3
                return $this->$property;
80
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
81
82 1
            case 'set':
83 1
                $this->$property = $arguments[0];
84 1
                break;
85
        }
86 1
        return false;
87
    }
88
}
89