AbstractEntityRepository::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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