PusherFactory::getConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0
1
<?php
2
namespace Tzsk\Push\Factory;
3
4
5
use Gomoob\Pushwoosh\Client\Pushwoosh;
6
use InvalidArgumentException;
7
8
class PusherFactory
9
{
10
    /**
11
     * Make a new Pushwoosh client.
12
     *
13
     * @return \Gomoob\Pushwoosh\Client\Pushwoosh
14
     */
15
    public function make()
16
    {
17
        $config = $this->getConfig();
18
19
        return $this->getClient($config);
20
    }
21
22
    /**
23
     * Get the configuration data.
24
     *
25
     * @throws \InvalidArgumentException
26
     *
27
     * @return array
28
     */
29
    protected function getConfig()
30
    {
31
        $cnf = config('push');
32
        $config = $cnf['connections'][$cnf['default']];
33
        $keys = ['key', 'token'];
34
35
        foreach ($keys as $key) {
36
            if (!array_key_exists($key, $config)) {
37
                throw new InvalidArgumentException("Missing configuration key [$key].");
38
            }
39
        }
40
41
        return array_only($config, $keys);
42
    }
43
44
    /**
45
     * Get the Pushwoosh client.
46
     *
47
     * @param string[] $auth
48
     *
49
     * @return \Gomoob\Pushwoosh\Client\Pushwoosh
50
     */
51
    protected function getClient(array $auth)
52
    {
53
        return Pushwoosh::create()
54
            ->setApplication($auth['key'])
55
            ->setAuth($auth['token']);
56
    }
57
58
}