TestimonialService::getTestimonials()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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