EventCategoryService::createEventCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services;
4
5
use App\Http\Requests\EventCategoryStoreRequest;
6
use App\Models\EventCategory;
7
use App\Repositories\EventCategoryRepository;
8
use Illuminate\Support\Collection;
9
10
class EventCategoryService
11
{
12
13
    private EventCategoryRepository $eventCategoryRepository;
14
15
    /**
16
     * EventCategoryService constructor.
17
     *
18
     * @param \App\Repositories\EventCategoryRepository $eventCategoryRepository
19
     */
20 5
    public function __construct(
21
        EventCategoryRepository $eventCategoryRepository
22
    ) {
23 5
        $this->eventCategoryRepository = $eventCategoryRepository;
24 5
    }
25
26
    /**
27
     * Create a EventCategory
28
     *
29
     * @param \App\Http\Requests\EventCategoryStoreRequest $request
30
     *
31
     * @return \App\Models\EventCategory
32
     */
33 1
    public function createEventCategory(EventCategoryStoreRequest $request): EventCategory
34
    {
35 1
        $eventCategory = $this->eventCategoryRepository->store($request->all());
36
37 1
        return $eventCategory;
38
    }
39
40
    /**
41
     * Update the EventCategory
42
     *
43
     * @param \App\Http\Requests\EventCategoryStoreRequest $request
44
     * @param int $eventCategoryId
45
     *
46
     * @return \App\Models\EventCategory
47
     */
48 1
    public function updateEventCategory(EventCategoryStoreRequest $request, int $eventCategoryId): EventCategory
49
    {
50 1
        $eventCategory = $this->eventCategoryRepository->update($request->all(), $eventCategoryId);
51
52 1
        return $eventCategory;
53
    }
54
55
    /**
56
     * Return the EventCategory from the database
57
     *
58
     * @param int $eventCategoryId
59
     *
60
     * @return \App\Models\EventCategory
61
     */
62 1
    public function getById(int $eventCategoryId): EventCategory
63
    {
64 1
        return $this->eventCategoryRepository->getById($eventCategoryId);
65
    }
66
67
    /**
68
     * Get all the EventCategories
69
     *
70
     * @return Collection
71
     */
72 1
    public function getEventCategories(): Collection
73
    {
74 1
        return $this->eventCategoryRepository->getAll();
75
    }
76
77
    /**
78
     * Delete the EventCategory from the database
79
     *
80
     * @param int $eventCategoryId
81
     */
82 1
    public function deleteEventCategory(int $eventCategoryId): void
83
    {
84 1
        $this->eventCategoryRepository->delete($eventCategoryId);
85 1
    }
86
87
}