Model   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 16
dl 0
loc 49
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A only() 0 9 3
A __construct() 0 3 1
A except() 0 12 4
A fill() 0 6 2
1
<?php
2
3
namespace Axsor\PhpIPAM\Models;
4
5
class Model
6
{
7
    public function __construct(array $data)
8
    {
9
        $this->fill($data);
10
    }
11
12
    public function fill($data)
13
    {
14
        $object = json_decode(json_encode($data));
15
16
        foreach (array_keys((array) $object) as $key) {
17
            $this->$key = $object->$key;
18
        }
19
    }
20
21
    public function toArray()
22
    {
23
        return (array) $this;
24
    }
25
26
    /**
27
     * @from laravel5.8
28
     * @param array $keys
29
     * @return array
30
     */
31
    public function only($keys)
32
    {
33
        $results = [];
34
35
        foreach (is_array($keys) ? $keys : func_get_args() as $key) {
36
            $results[$key] = $this->$key;
37
        }
38
39
        return $results;
40
    }
41
42
    public function except($keys)
43
    {
44
        $results = [];
45
        $except = is_array($keys) ? $keys : [$keys];
46
47
        foreach (array_keys($this->toArray()) as $key) {
48
            if (! in_array($key, $except)) {
49
                $results[$key] = $this->$key;
50
            }
51
        }
52
53
        return $results;
54
    }
55
}
56