Completed
Push — dev ( b3efe2...6e9976 )
by Arnaud
02:54
created

DataProvider::findBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 4
crap 1
1
<?php
2
3
namespace LAG\AdminBundle\DataProvider;
4
5
use Doctrine\Common\Collections\Collection;
6
use LAG\DoctrineRepositoryBundle\Repository\RepositoryInterface;
7
8
/**
9
 * Default data provider using generic repositories
10
 */
11
class DataProvider implements DataProviderInterface
12
{
13
    /**
14
     * @var RepositoryInterface
15
     */
16
    protected $repository;
17
18
    /**
19
     * DataProvider constructor.
20
     *
21
     * @param RepositoryInterface $repository
22
     */
23 10
    public function __construct(
24
        RepositoryInterface $repository
25
    ) {
26 10
        $this->repository = $repository;
27 10
    }
28
29
    /**
30
     * Find entities by criteria.
31
     *
32
     * @param array $criteria
33
     * @param array $orderBy
34
     * @param int|null $limit
35
     * @param int|null $offset
36
     * @return Collection|array
37
     */
38 1
    public function findBy(array $criteria = [], $orderBy = [], $limit = null, $offset = null)
39
    {
40 1
        return $this
41
            ->repository
42 1
            ->findBy($criteria, $orderBy, $limit, $offset);
43
    }
44
45
    /**
46
     * Find an entity by its unique id.
47
     *
48
     * @param $id
49
     * @return object
50
     */
51 1
    public function find($id)
52
    {
53 1
        return $this
54
            ->repository
55 1
            ->find($id);
56
    }
57
58
    /**
59
     * Save an entity.
60
     *
61
     * @param $entity
62
     */
63 1
    public function save($entity)
64
    {
65 1
        $this
66
            ->repository
67 1
            ->save($entity);
68 1
    }
69
70
    /**
71
     * Remove an entity.
72
     *
73
     * @param $entity
74
     */
75 1
    public function remove($entity)
76
    {
77 1
        $this
78
            ->repository
79 1
            ->delete($entity);
80 1
    }
81
82
    /**
83
     * Create a new entity.
84
     *
85
     * @return object
86
     */
87 1
    public function create()
88
    {
89 1
        $className = $this->repository->getClassName();
90
91 1
        return new $className;
92
    }
93
}
94