Completed
Push — master ( ab58ed...829fed )
by Дмитрий
04:32
created

Service::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Auth;
8
9
use Exception;
10
use SocialConnect\Common\HttpClient;
11
12
/**
13
 * Class Service
14
 * @package SocialConnect\Auth
15
 */
16
class Service
17
{
18
    use HttpClient;
19
20
    /**
21
     * @var FactoryInterface
22
     */
23
    protected $factory;
24
25
    /**
26
     * @var array
27
     */
28
    protected $config;
29
30
    /**
31
     * @param array $config
32
     * @param null $factory
33
     * @internal param $storage
34
     */
35 8
    public function __construct(array $config, $factory = null)
36
    {
37 8
        $this->config = $config;
38 8
        $this->factory = is_null($factory) ? new Factory() : $factory;
39 8
    }
40
41
    /**
42
     * @param $name
43
     * @return array
44
     * @throws Exception
45
     */
46 1
    public function getProviderConfiguration($name)
47
    {
48 1
        if (isset($this->config['provider'][ucfirst($name)])) {
49 1
            return $this->config['provider'][ucfirst($name)];
50
        }
51
52
        throw new Exception('Please setup configuration for ' . ucfirst($name) . ' provider');
53
    }
54
55
    /**
56
     * Get provider class by $name
57
     *
58
     * @param $name
59
     * @return \SocialConnect\Auth\AbstractBaseProvider
60
     * @throws Exception
61
     */
62 1
    public function getProvider($name)
63
    {
64 1
        return $this->factory->factory(ucfirst($name), $this->getProviderConfiguration($name), $this);
65
    }
66
67
    /**
68
     * @return array
69
     */
70 1
    public function getConfig()
71
    {
72 1
        return $this->config;
73
    }
74
75
    /**
76
     * @return FactoryInterface
77
     */
78
    public function getFactory()
79
    {
80
        return $this->factory;
81
    }
82
}
83