Completed
Pull Request — master (#6)
by
unknown
03:48 queued 10s
created

VariableResolver::resolve()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 19
ccs 0
cts 10
cp 0
crap 12
rs 9.9332
1
<?php
2
3
namespace Slides\Connector\Auth\Clients\Mandrill;
4
5
use Exception;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Str;
8
9
/**
10
 * Class VariableResolver
11
 *
12
 * @package Slides\Connector\Auth\Clients\Mandrill
13
 */
14
class VariableResolver
15
{
16
    /**
17
     * @var Collection
18
     */
19
    protected $emails;
20
21
    /**
22
     * VariableResolver constructor.
23
     *
24
     * @param Collection $emails
25
     */
26
    final public function __construct(Collection $emails)
27
    {
28
        $this->emails = $emails;
29
30
        if (method_exists($this, 'boot')) {
31
            app()->call([$this, 'boot']);
32
        }
33
    }
34
35
    /**
36
     * Resolver given variable.
37
     *
38
     * @param string $variable
39
     * @param string $email
40
     *
41
     * @return array
42
     *
43
     * @throws Exception
44
     */
45
    final public function resolve(string $variable, string $email): array
46
    {
47
        $name = Str::before($variable, ':');
48
49
        $arguments[] = $email;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$arguments was never initialized. Although not strictly required by PHP, it is generally a good practice to add $arguments = array(); before regardless.
Loading history...
50
51
        if (Str::contains($variable, ':')) {
52
            $arguments = array_merge($arguments, explode(',', Str::after($variable, $name . ':')));
53
        }
54
55
        $method = 'get' . ucfirst($name) . 'Variable';
56
57
        if (!method_exists($this, $method)) {
58
            throw new Exception('Method ' . $method . ' should be defined.');
59
        }
60
61
        return [
62
            'name' => $name,
63
            'content' => call_user_func([$this, $method], ...$arguments)
64
        ];
65
    }
66
}