PusherFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 6 1
A getConfig() 0 14 3
A getClient() 0 6 1
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
}