Passed
Push — master ( 2f8437...bbe808 )
by Radosław
02:25
created

Item::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
crap 3.576
1
<?php
2
3
namespace Radowoj\Searcher\SearchResult;
4
5
class Item implements IItem
6
{
7
    protected $url = '';
8
9
    protected $title = null;
10
11
    protected $description = null;
12
13
14 7
    public function __construct(array $data)
15
    {
16 7
        $this->fromArray($data);
17 7
    }
18
19
20 7
    protected function fromArray(array $data)
21
    {
22 7
        foreach($data as $key => $value) {
23
            if (property_exists($this, $key)) {
24
                $this->{$key} = $value;
25
            }
26
        }
27 7
    }
28
29
30
    public function toArray()
31
    {
32
        return [
33
            'url'           => $this->url,
34
            'title'         => $this->title,
35
            'description'   => $this->description,
36
        ];
37
    }
38
39
40
    public function __toString()
41
    {
42
        return $this->url;
43
    }
44
45
46
47
}
48