AbstractDataRow::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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