These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Dontdrinkandroot\Service; |
||
4 | |||
5 | use Doctrine\ORM\Tools\Pagination\Paginator; |
||
6 | use Dontdrinkandroot\Repository\CrudRepositoryInterface; |
||
7 | |||
8 | /** |
||
9 | * @author Philip Washington Sorst <[email protected]> |
||
10 | */ |
||
11 | class RepositoryCrudService implements CrudServiceInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var CrudRepositoryInterface |
||
15 | */ |
||
16 | private $repository; |
||
17 | |||
18 | 10 | public function __construct(CrudRepositoryInterface $repository) |
|
19 | { |
||
20 | 10 | $this->repository = $repository; |
|
21 | 10 | } |
|
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 2 | public function find($id): ?object |
|
27 | { |
||
28 | 2 | return $this->getRepository()->find($id); |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 4 | public function findAll(): array |
|
35 | { |
||
36 | 4 | return $this->getRepository()->findAll(); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function findAllPaginated(int $page = 1, int $perPage = 50): Paginator |
||
43 | { |
||
44 | return $this->getRepository()->findPaginatedBy($page, $perPage); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 2 | public function create(object $entity): object |
|
51 | { |
||
52 | 2 | return $this->getRepository()->persist($entity, true); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 2 | public function update(object $entity): object |
|
59 | { |
||
60 | 2 | $this->getRepository()->flush($entity); |
|
0 ignored issues
–
show
|
|||
61 | |||
62 | 2 | return $entity; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 4 | public function save(object $entity): object |
|
69 | { |
||
70 | 4 | return $this->getRepository()->merge($entity, true); |
|
0 ignored issues
–
show
|
|||
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function remove(object $entity): void |
||
77 | { |
||
78 | $this->getRepository()->remove($entity, true); |
||
79 | } |
||
80 | |||
81 | 10 | protected function getRepository(): CrudRepositoryInterface |
|
82 | { |
||
83 | 10 | return $this->repository; |
|
84 | } |
||
85 | } |
||
86 |
This method has been deprecated.