Passed
Push — master ( 5bff59...6028dd )
by Vitaliy
03:27
created

AbstractRow   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 53
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
hasInternal() 0 1 ?
getInternal() 0 1 ?
A __construct() 0 4 1
A get() 0 6 3
A has() 0 4 2
A dynamicFieldsRegistry() 0 4 1
A toArray() 0 4 1
A toObject() 0 12 3
A extract() 0 4 2
1
<?php
2
3
namespace Nayjest\Querying\Row;
4
5
abstract class AbstractRow implements RowInterface
6
{
7
    protected $dynamicFields;
8
9
    abstract protected function hasInternal($fieldName);
10
11
    abstract protected function getInternal($fieldName);
12
13 11
    public function __construct(DynamicFieldsRegistry $dynamicFields)
14
    {
15 11
        $this->dynamicFields = $dynamicFields;
16 11
    }
17
18 5
    public function get($fieldName, $default = null)
19
    {
20 5
        return $this->hasInternal($fieldName) ? $this->getInternal($fieldName) : (
21 3
            $this->dynamicFields->has($fieldName) ? $this->dynamicFields->get($fieldName, $this) : $default
22 5
        );
23
    }
24
25 2
    public function has($fieldName)
26
    {
27 2
        return $this->hasInternal($fieldName) || $this->dynamicFields->has($fieldName);
28
    }
29
30 3
    public function dynamicFieldsRegistry()
31
    {
32 3
        return $this->dynamicFields;
33
    }
34
35 2
    public function toArray()
36
    {
37 2
        return array_merge((array)$this->getSrc(), $this->dynamicFieldsRegistry()->getAll($this));
38
    }
39
40 2
    public function toObject()
41
    {
42 2
        $src = $this->getSrc();
43 2
        if (!is_object($src)) {
44 1
            $src = (object)$src;
45 1
        }
46 2
        $dynamicFields = $this->dynamicFieldsRegistry()->getAll($this);
47 2
        foreach($dynamicFields as $key => $value) {
48 2
            $src->{$key} = $value;
49 2
        }
50 2
        return $src;
51
    }
52
53
    public function extract()
54
    {
55
        return is_array($this->getSrc()) ? $this->toArray() : $this->toObject();
56
    }
57
}
58