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

Item   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 43
ccs 6
cts 14
cp 0.4286
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 1
A __toString() 0 4 1
A __construct() 0 4 1
A fromArray() 0 8 3
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