EventsService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 15
c 3
b 0
f 1
dl 0
loc 58
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getUnsetFields() 0 3 1
A getEvent() 0 3 1
A deleteBanner() 0 10 2
A getParentRelationship() 0 3 1
1
<?php
2
3
namespace Innoflash\Events\Services;
4
5
use FaithGen\SDK\Traits\FileTraits;
6
use Innoflash\Events\Models\Event;
7
use InnoFlash\LaraStart\Services\CRUDServices;
8
9
class EventsService extends CRUDServices
10
{
11
    use FileTraits;
12
13
    protected Event $event;
14
15
    public function __construct()
16
    {
17
        $this->event = app(Event::class);
18
19
        $eventId = request()->route('event') ?? request('event_id');
20
21
        if ($eventId) {
22
            $this->event = $this->event->resolveRouteBinding($eventId);
23
        }
24
    }
25
26
    /**
27
     * Retrieves an instance of event.
28
     *
29
     * @return \Innoflash\Events\Models\Event
30
     */
31
    public function getEvent(): Event
32
    {
33
        return $this->event;
34
    }
35
36
    /**
37
     * Makes a list of fields that you do not want to be sent
38
     * to the create or update methods.
39
     * Its mainly the fields that you do not have in the messages table.
40
     *
41
     * @return array
42
     */
43
    public function getUnsetFields(): array
44
    {
45
        return ['event_id', 'banner'];
46
    }
47
48
    /**
49
     * Attaches a parent to the current event
50
     * You can delete this if you do not intent to create events from parent relationships.
51
     */
52
    public function getParentRelationship()
53
    {
54
        return auth()->user()->events();
55
    }
56
57
    public function deleteBanner($event)
58
    {
59
        if ($event->image()->exists()) {
60
            $this->deleteFiles($event);
61
            $event->image()->delete();
62
63
            return $this->successResponse('Banner deleted');
64
        }
65
66
        return $this->successResponse('This event doesn`t have a banner already');
67
    }
68
}
69