Model   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 100
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A first() 0 3 1
A offsetSet() 0 8 2
A offsetExists() 0 5 1
A offsetGet() 0 5 2
A toArray() 0 3 1
A offsetUnset() 0 5 1
A toList() 0 9 2
A end() 0 2 1
A count() 0 3 1
1
<?php
2
3
namespace MocOrm\Support;
4
5
/**
6
 * Class Model
7
 * @package MocOrm\Support
8
 */
9
abstract class Model extends \MocOrm\Model\Model implements \ArrayAccess
10
{
11
    /**
12
     * Gets model data.
13
     *
14
     * @return array
15
     */
16
    public function toArray()
17
    {
18
        return $this->getData();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getData() also could return the type boolean which is incompatible with the documented return type array.
Loading history...
19
    }
20
21
    /**
22
     * Return count of data
23
     * @return int
24
     */
25
    public function count()
26
    {
27
        return count($this->getData());
0 ignored issues
show
Bug introduced by
It seems like $this->getData() can also be of type boolean; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        return count(/** @scrutinizer ignore-type */ $this->getData());
Loading history...
28
    }
29
30
    /**
31
     * Get first model from query result.
32
     * @return mixed
33
     */
34
    public function end() {
35
        return end($this->getData());
0 ignored issues
show
Bug introduced by
It seems like $this->getData() can also be of type boolean; however, parameter $array of end() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return end(/** @scrutinizer ignore-type */ $this->getData());
Loading history...
36
    }
37
38
    /**
39
     * Gets model data through static method.
40
     *
41
     * @param  mixed $data
42
     * @return array
43
     */
44
    public static function toList($data)
45
    {
46
        if (!($data instanceof self)) throw new \Exception(" It's not a model.");
47
48
        $data = array_map(function ($object) {
49
            return $object->toArray();
50
        }, $data);
0 ignored issues
show
Bug introduced by
$data of type MocOrm\Support\Model is incompatible with the type array expected by parameter $arr1 of array_map(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        }, /** @scrutinizer ignore-type */ $data);
Loading history...
51
52
        return $data;
53
    }
54
55
    /**
56
     * Get first model from query result.
57
     *
58
     * @return mixed
59
     */
60
    public function first()
61
    {
62
        return current($this->getData());
0 ignored issues
show
Bug introduced by
It seems like $this->getData() can also be of type boolean; however, parameter $array of current() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        return current(/** @scrutinizer ignore-type */ $this->getData());
Loading history...
63
    }
64
65
    /**
66
     * ArrayAccess Interface.
67
     */
68
    public function offsetExists($offset)
69
    {
70
        $data = $this->getData();
71
72
        return isset($data[$offset]);
73
    }
74
75
    /**
76
     * @param mixed $offset
77
     * @return mixed|null
78
     */
79
    public function offsetGet($offset)
80
    {
81
        $data = $this->getData();
82
83
        return isset($data[$offset]) ? $data[$offset] : null;
84
    }
85
86
    /**
87
     * @param mixed $offset
88
     * @param mixed $value
89
     */
90
    public function offsetSet($offset, $value)
91
    {
92
        $data = $this->getData();
93
94
        if (is_null($offset)) {
95
            $data[] = $value;
96
        } else {
97
            $data[$offset] = $value;
98
        }
99
    }
100
101
    /**
102
     * @param mixed $offset
103
     */
104
    public function offsetUnset($offset)
105
    {
106
        $data = $this->getData();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
107
108
        unset($this->data[$offset]);
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist on MocOrm\Support\Model. Since you implemented __get, consider adding a @property annotation.
Loading history...
109
    }
110
}
111