MessageService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getMessage() 0 3 1
A getModel() 0 3 1
A getUnsetFields() 0 3 1
A getParentRelationship() 0 3 1
1
<?php
2
3
namespace FaithGen\Messages;
4
5
use FaithGen\Messages\Models\Message;
6
use InnoFlash\LaraStart\Services\CRUDServices;
7
8
class MessageService extends CRUDServices
9
{
10
    /**
11
     * @var Message
12
     */
13
    private $message;
14
15
    public function __construct(Message $message)
16
    {
17
        if (request()->has('message_id')) {
18
            $this->message = Message::findOrFail(request('message_id'));
19
        } else {
20
            $this->message = $message;
21
        }
22
    }
23
24
    /**
25
     * @return Message
26
     */
27
    public function getMessage(): Message
28
    {
29
        return $this->message;
30
    }
31
32
    /**
33
     * This sets the attributes to be removed from the given set for updating or creating.
34
     * @return mixed
35
     */
36
    public function getUnsetFields()
37
    {
38
        return 'message_id';
39
    }
40
41
    /**
42
     * This get the model value or class of the model in the service.
43
     * @return mixed
44
     */
45
    public function getModel()
46
    {
47
        return $this->getMessage();
48
    }
49
50
    public function getParentRelationship()
51
    {
52
        return auth()->user()->messages();
53
    }
54
}
55