PostCategoryService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 75
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createPostCategory() 0 5 1
A getPostCategories() 0 3 1
A updatePostCategory() 0 5 1
A __construct() 0 4 1
A deletePostCategory() 0 3 1
A getById() 0 3 1
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
}