Test Setup Failed
Push — main ( 1f6960...c530ab )
by Davide
01:22 queued 12s
created

TeacherService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
namespace App\Services;
3
4
use App\Helpers\ImageHelpers;
5
use App\Http\Requests\TeacherStoreRequest;
6
use App\Models\Teacher;
7
use App\Repositories\TeacherRepositoryInterface;
8
9
class TeacherService
10
{
11
    private TeacherRepositoryInterface $teacherRepository;
12
13
    /**
14
     * TestimonialService constructor.
15
     *
16
     * @param  TeacherRepositoryInterface  $teacherRepository
17
     */
18
    public function __construct(
19 6
        TeacherRepositoryInterface $teacherRepository
20
    ) {
21
        $this->teacherRepository = $teacherRepository;
22 6
    }
23 6
24
    /**
25
     * Create a teacher
26
     *
27
     * @param \App\Http\Requests\TeacherStoreRequest $request
28
     *
29
     * @return \App\Models\Teacher
30
     * @throws \Spatie\ModelStatus\Exceptions\InvalidStatus
31
     */
32
    public function createTeacher(TeacherStoreRequest $request): Teacher
33 1
    {
34
        $teacher = $this->teacherRepository->store($request->all());
35 1
        ImageHelpers::storeImages($teacher, $request, 'profile_picture');
36 1
37
        return $teacher;
38 1
    }
39
40 1
    /**
41
     * Update the Teacher
42
     *
43
     * @param \App\Http\Requests\TeacherStoreRequest $request
44
     * @param int $teacherId
45
     *
46
     * @return \App\Models\Teacher
47
     */
48
    public function updateTeacher(TeacherStoreRequest $request, int $teacherId): Teacher
49
    {
50
        $teacher = $this->teacherRepository->update($request->all(), $teacherId);
51 1
52
        ImageHelpers::storeImages($teacher, $request, 'profile_picture');
53 1
        ImageHelpers::deleteImages($teacher, $request, 'profile_picture');
54
55 1
        return $teacher;
56 1
    }
57
58 1
    /**
59
     * Return the teacher from the database
60
     *
61
     * @param int $teacherId
62
     *
63
     * @return \App\Models\Teacher
64
     */
65
    public function getById(int $teacherId): Teacher
66
    {
67
        return $this->teacherRepository->getById($teacherId);
68 1
    }
69
70 1
    /**
71
     * Return the teacher from the database
72
     *
73
     * @param  string  $teacherSlug
74
     * @return Teacher
75
     */
76
    public function getBySlug(string $teacherSlug): Teacher
77
    {
78
        return $this->teacherRepository->getBySlug($teacherSlug);
79
    }
80
81 1
    /**
82
     * Get all the Teachers.
83 1
     *
84
     * @param int|null $recordsPerPage
85
     * @param array|null $searchParameters
86
     *
87
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator
88
     */
89
    public function getTeachers(int $recordsPerPage = null, array $searchParameters = null)
90
    {
91 1
        return $this->teacherRepository->getAll($recordsPerPage, $searchParameters);
92
    }
93 1
94 1
    /**
95
     * Delete the teacher from the database
96
     *
97
     * @param int $teacherId
98
     */
99
    public function deleteTeacher(int $teacherId): void
100
    {
101 1
        $this->teacherRepository->delete($teacherId);
102
    }
103 1
104
    /**
105
     * Get the number of teacher created in the last 30 days.
106
     *
107
     * @return int
108
     */
109
    public function getNumberTeachersCreatedLastThirtyDays(): int
110
    {
111
        return Teacher::whereDate('created_at', '>', date('Y-m-d', strtotime('-30 days')))->count();
112
    }
113
114
}
115