Completed
Pull Request — master (#1)
by Luc
05:20 queued 02:30
created

CategoryDoctrineRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Repositories;
4
5
use Ramsey\Uuid\UuidInterface;
6
use VSV\GVQ_API\Question\Models\Categories;
7
use VSV\GVQ_API\Question\Models\Category;
8
9
class CategoryDoctrineRepository extends AbstractDoctrineRepository implements CategoryRepository
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function getRepositoryName(): string
15
    {
16
        return Category::class;
17
    }
18
19
    /**
20
     * @param Category $category
21
     */
22
    public function save(Category $category): void
23
    {
24
        $this->entityManager->persist($category);
25
        $this->entityManager->flush();
26
    }
27
28
    /**
29
     * @param Category $category
30
     */
31
    public function update(Category $category): void
32
    {
33
        $this->entityManager->merge($category);
34
        $this->entityManager->flush();
35
    }
36
37
    /**
38
     * @param Category $category
39
     */
40
    public function delete(Category $category): void
41
    {
42
        $category = $this->entityManager->merge($category);
43
        $this->entityManager->remove($category);
44
        $this->entityManager->flush();
45
    }
46
47
    /**
48
     * @param UuidInterface $id
49
     * @return Category|null
50
     */
51
    public function getById(UuidInterface $id): ?Category
52
    {
53
        /** @var Category|null $category */
54
        $category = $this->objectRepository->findOneBy(
55
            [
56
                'id' => $id,
57
            ]
58
        );
59
60
        return $category;
61
    }
62
63
    /**
64
     * @return Categories|null
65
     */
66
    public function getAll(): ?Categories
67
    {
68
        /** @var Category[] $categories */
69
        $categories = $this->objectRepository->findAll();
70
71
        if (empty($categories)) {
72
            return null;
73
        }
74
75
        return new Categories(...$categories);
76
    }
77
}
78