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

VariableResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 50
ccs 0
cts 15
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 19 3
A __construct() 0 6 2
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
}