Test Setup Failed
Push — main ( 517fbc...18e063 )
by Davide
01:16 queued 11s
created

OrganizerService::getBySlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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