Completed
Push — master ( 368143...d51541 )
by Maxim
02:29
created

AbstractEntityRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\entity;
4
5
use WebComplete\core\factory\ObjectFactory;
6
use WebComplete\core\utils\hydrator\HydratorInterface;
7
8
abstract class AbstractEntityRepository implements EntityRepositoryInterface
9
{
10
11
    /**
12
     * @var ObjectFactory
13
     */
14
    protected $factory;
15
16
    /**
17
     * @var HydratorInterface
18
     */
19
    protected $hydrator;
20
21
    /**
22
     * @param ObjectFactory $factory
23
     * @param HydratorInterface $hydrator
24
     */
25
    public function __construct(ObjectFactory $factory, HydratorInterface $hydrator)
26
    {
27
        $this->factory = $factory;
28
        $this->hydrator = $hydrator;
29
    }
30
31
    /**
32
     * @return AbstractEntity
33
     */
34
    public function create(): AbstractEntity
35
    {
36
        $result = $this->factory->create();
37
        /** @var AbstractEntity $result */
38
        return $result;
39
    }
40
41
    /**
42
     * @param array $data
43
     * @param array|null $map
44
     *
45
     * @return AbstractEntity
46
     */
47
    public function createFromData(array $data, array $map = null): AbstractEntity
48
    {
49
        $result = $this->factory->createFromData($data, $map);
50
        /** @var AbstractEntity $result */
51
        return $result;
52
    }
53
54
    /**
55
     * Adjust data before save
56
     * @param $data
57
     */
58
    abstract protected function beforeDataSave(&$data);
59
}
60