GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CreateSMSHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace LBHurtado\Missive\Handlers;
4
5
use LBHurtado\Missive\Facades\Missive;
6
use LBHurtado\Missive\Repositories\SMSRepository;
7
use LBHurtado\Tactician\Contracts\CommandInterface;
8
use LBHurtado\Tactician\Contracts\HandlerInterface;
9
10
class CreateSMSHandler implements HandlerInterface
11
{
12
    /** @var SMSRepository  */
13
    protected $smss;
14
15
    /**
16
     * CreateSMSHandler constructor.
17
     * @param SMSRepository $smss
18
     */
19
    public function __construct(SMSRepository $smss)
20
    {
21
        $this->smss = $smss;
22
    }
23
24
    /**
25
     * Persist the missive in the database using
26
     * the repository create method and command attributes.
27
     *
28
     * @param CommandInterface $command
29
     */
30
    public function handle(CommandInterface $command)
31
    {
32
        $this->smss->create($this->getCommandAttributes($command));
33
    }
34
35
    /**
36
     * Arrange the attributes for creating the model.
37
     *
38
     * If the relay provider is telerivet:
39
     *
40
     *  from
41
     *
42
     *  [
43
     *      'secret' => 'ABC12344567890', //miscellaneous field
44
     *      'from_number' => '+639171234567',
45
     *      'to_number' => '+639187654321',
46
     *      'content' => 'The quick brown fox...',
47
     *  ]
48
     *
49
     *  to
50
     *
51
     *  [
52
     *      'from' => '+639171234567',
53
     *      'to' => '+639187654321',
54
     *      'message' => 'The quick brown fox...',
55
     *  ]
56
     *
57
     * @param CommandInterface $command
58
     * @return array
59
     */
60
    protected function getCommandAttributes(CommandInterface $command): array
61
    {
62
        return optional(Missive::getRelayProviderConfig(), function ($mapping) use ($command) {
63
            $attributes = [];
64
            $properties = $command->getProperties();
65
            foreach ($this->getSMSFields() as $field) {
66
                $property = $mapping[$field];
67
                $attributes[$field] = $properties[$property];
68
            }
69
70
            return $attributes;
71
        });
72
    }
73
74
    /**
75
     * Extract the fields of the SMS model e.g.
76
     *
77
     *  [
78
     *      'from',
79
     *      'to',
80
     *      'message',
81
     *  ]
82
     *
83
     * @return mixed
84
     */
85
    protected function getSMSFields()
86
    {
87
        return app($this->smss->model())->getFillable();
88
    }
89
}
90