PostCategoryService::deletePostCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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\PostCategoryStoreRequest;
6
use App\Models\PostCategory;
7
use App\Repositories\PostCategoryRepository;
8
use Illuminate\Support\Collection;
9
10
class PostCategoryService
11
{
12
13
    private PostCategoryRepository $postCategoryRepository;
14
15
    /**
16
     * PostCategoryService constructor.
17
     *
18
     * @param \App\Repositories\PostCategoryRepository $postCategoryRepository
19
     */
20 5
    public function __construct(
21
        PostCategoryRepository $postCategoryRepository
22
    ) {
23 5
        $this->postCategoryRepository = $postCategoryRepository;
24 5
    }
25
26
    /**
27
     * Create a PostCategory
28
     *
29
     * @param \App\Http\Requests\PostCategoryStoreRequest $request
30
     *
31
     * @return \App\Models\PostCategory
32
     */
33 1
    public function createPostCategory(PostCategoryStoreRequest $request): PostCategory
34
    {
35 1
        $postCategory = $this->postCategoryRepository->store($request->all());
36
37 1
        return $postCategory;
38
    }
39
40
    /**
41
     * Update the PostCategory
42
     *
43
     * @param \App\Http\Requests\PostCategoryStoreRequest $request
44
     * @param int $postCategoryId
45
     *
46
     * @return \App\Models\PostCategory
47
     */
48 1
    public function updatePostCategory(PostCategoryStoreRequest $request, int $postCategoryId): PostCategory
49
    {
50 1
        $postCategory = $this->postCategoryRepository->update($request->all(), $postCategoryId);
51
52 1
        return $postCategory;
53
    }
54
55
    /**
56
     * Return the PostCategory from the database
57
     *
58
     * @param int $postCategoryId
59
     *
60
     * @return \App\Models\PostCategory
61
     */
62 1
    public function getById(int $postCategoryId): PostCategory
63
    {
64 1
        return $this->postCategoryRepository->getById($postCategoryId);
65
    }
66
67
    /**
68
     * Get all the PostCategoriess
69
     *
70
     * @return Collection
71
     */
72 1
    public function getPostCategories(): Collection
73
    {
74 1
        return $this->postCategoryRepository->getAll();
75
    }
76
77
    /**
78
     * Delete the PostCategory from the database
79
     *
80
     * @param int $postCategoryId
81
     */
82 1
    public function deletePostCategory(int $postCategoryId): void
83
    {
84 1
        $this->postCategoryRepository->delete($postCategoryId);
85 1
    }
86
87
}