AbstractDataRow   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHydrator() 0 6 1
A toJson() 0 3 1
A __construct() 0 4 2
A toArray() 0 3 1
1
<?php
2
3
namespace App\DataRow;
4
5
use Zend\Hydrator\NamingStrategy\UnderscoreNamingStrategy;
6
use Zend\Hydrator\ObjectProperty as Hydrator;
7
8
/**
9
 * Class AbstractDataRow.
10
 */
11
abstract class AbstractDataRow implements DataRowInterface
12
{
13
    /**
14
     * BaseEntity constructor.
15
     *
16
     * @todo rename datarow to entity
17
     *
18
     * @param array $row 
19
     */
20
    public function __construct(array $row = null)
21
    {
22
        if ($row) {
23
            $this->getHydrator()->hydrate($row, $this);
24
        }
25
    }
26
27
    /**
28
     * Get Hydrator.
29
     *
30
     * @return Hydrator Hydrator
31
     */
32
    protected function getHydrator()
33
    {
34
        $hydrator = new Hydrator();
35
        $hydrator->setNamingStrategy(new UnderscoreNamingStrategy());
36
37
        return $hydrator;
38
    }
39
40
    /**
41
     * Extract objects to arrays.
42
     *
43
     * @return array
44
     */
45
    public function toArray()
46
    {
47
        return $this->getHydrator()->extract($this);
48
    }
49
50
    /**
51
     * To json.
52
     *
53
     * @return string Json
54
     */
55
    public function toJson()
56
    {
57
        return json_encode($this->toArray());
58
    }
59
}
60