Test Failed
Push — master ( 8cc230...986bb1 )
by Robin
10:35
created

Model::fill()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Konsulting\JustGivingApiSdk\ResourceClients\Models;
4
5
class Model
6
{
7
    /**
8
     * Allow data to be filled via the constructor.
9
     *
10
     * @param iterable $data
11
     */
12 27
    public function __construct($data = null)
13
    {
14 27
        if (isset($data)) {
15 23
            $this->fill($data);
16
        }
17 27
    }
18
19
    /**
20
     * Get an associative array of the attributes.
21
     *
22
     * @return array
23
     */
24 27
    public function getAttributes()
25
    {
26 27
        return get_object_vars($this);
27
    }
28
29
    /**
30
     * Get the names of the attributes on this model.
31
     *
32
     * @return array
33
     */
34 1
    public function getAttributeNames()
35
    {
36 1
        return array_keys($this->getAttributes());
37
    }
38
39
    /**
40
     * Populate the model with the supplied data.
41
     *
42
     * @param iterable $data
43
     * @return $this
44
     */
45 25
    public function fill($data)
46
    {
47 25
        foreach ($data as $key => $value) {
48 25
            $this->$key = $value;
49
        }
50
51 25
        return $this;
52
    }
53
}
54