VariableResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 14
c 3
b 0
f 0
dl 0
loc 63
ccs 0
cts 14
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 11 2
A get() 0 3 1
A __construct() 0 7 2
1
<?php
2
3
namespace Slides\Connector\Auth\Clients\Mandrill;
4
5
use Exception;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Collection;
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
     * @var array
23
     */
24
    protected $context;
25
26
    /**
27
     * VariableResolver constructor.
28
     *
29
     * @param Collection $emails
30
     * @param array $context
31
     */
32
    final public function __construct(Collection $emails, array $context)
33
    {
34
        $this->emails = $emails;
35
        $this->context = $context;
36
37
        if (method_exists($this, 'boot')) {
38
            app()->call([$this, 'boot']);
39
        }
40
    }
41
42
    /**
43
     * Resolver given variable.
44
     *
45
     * @param string $name
46
     * @param string $email
47
     *
48
     * @return array
49
     *
50
     * @throws Exception
51
     */
52
    final public function resolve(string $name, string $email): array
53
    {
54
        $method = 'get' . ucfirst($name) . 'Variable';
55
56
        if (!method_exists($this, $method)) {
57
            throw new Exception('Method ' . $method . ' should be defined.');
58
        }
59
60
        return [
61
            'name' => $name,
62
            'content' => call_user_func([$this, $method], $email)
63
        ];
64
    }
65
66
    /**
67
     * Get the variables from the context.
68
     *
69
     * @param string $key
70
     * @param mixed $default
71
     *
72
     * @return mixed
73
     */
74
    protected function get(string $key, $default = null)
75
    {
76
        return Arr::get($this->context, $key, $default);
77
    }
78
}