TestimonialService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 81
ccs 18
cts 18
cp 1
rs 10
c 3
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteTestimonial() 0 3 1
A getById() 0 3 1
A getTestimonials() 0 3 1
A updateTestimonial() 0 8 1
A createTestimonial() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Services;
4
5
use App\Helpers\ImageHelpers;
6
use App\Http\Requests\TestimonialSearchRequest;
7
use App\Http\Requests\TestimonialStoreRequest;
8
use App\Models\Testimonial;
9
use App\Repositories\TestimonialRepository;
10
11
class TestimonialService
12
{
13
    private TestimonialRepository $testimonialRepository;
14
15
    /**
16
     * TestimonialService constructor.
17
     *
18
     * @param \App\Repositories\TestimonialRepository $testimonialRepository
19
     */
20 5
    public function __construct(TestimonialRepository $testimonialRepository)
21
    {
22 5
        $this->testimonialRepository = $testimonialRepository;
23 5
    }
24
25
    /**
26
     * Return the testimonial from the database
27
     *
28
     * @param int $testimonialId
29
     *
30
     * @return \App\Models\Testimonial
31
     */
32 1
    public function getById(int $testimonialId): Testimonial
33
    {
34 1
        return $this->testimonialRepository->getById($testimonialId);
35
    }
36
37
    /**
38
     * Get all the Testimonials.
39
     *
40
     * @param int|null $recordsPerPage
41
     * @param array|null $searchParameters
42
     *
43
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
44
     */
45 1
    public function getTestimonials(int $recordsPerPage = null, array $searchParameters = null)
46
    {
47 1
        return $this->testimonialRepository->getAll($recordsPerPage, $searchParameters);
48
    }
49
50
    /**
51
     * Create a Testimonial
52
     *
53
     * @param \App\Http\Requests\TestimonialStoreRequest $request
54
     *
55
     * @return \App\Models\Testimonial
56
     */
57 1
    public function createTestimonial(TestimonialStoreRequest $request): Testimonial
58
    {
59 1
        $testimonial = $this->testimonialRepository->store($request->all());
60
61 1
        ImageHelpers::storeImages($testimonial, $request, 'photo');
62
63 1
        return $testimonial;
64
    }
65
66
    /**
67
     * Update the Testimonial
68
     *
69
     * @param \App\Http\Requests\TestimonialStoreRequest $request
70
     * @param int $testimonialId
71
     *
72
     * @return \App\Models\Testimonial
73
     */
74 1
    public function updateTestimonial(TestimonialStoreRequest $request, int $testimonialId): Testimonial
75
    {
76 1
        $testimonial = $this->testimonialRepository->update($request->all(), $testimonialId);
77
78 1
        ImageHelpers::storeImages($testimonial, $request, 'photo');
79 1
        ImageHelpers::deleteImages($testimonial, $request, 'photo');
80
81 1
        return $testimonial;
82
    }
83
84
    /**
85
     * Delete the Testimonial from the database
86
     *
87
     * @param int $testimonialId
88
     */
89 1
    public function deleteTestimonial(int $testimonialId): void
90
    {
91 1
        $this->testimonialRepository->delete($testimonialId);
92 1
    }
93
94
}
95