Completed
Push — master ( 7e4f78...5ca817 )
by Filippo
02:47
created

GuzzleHttpConnector::getConfig()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
c 0
b 0
f 0
rs 9.2
cc 4
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel SMSFactor.
5
 *
6
 * (c) Filippo Galante <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace IlGala\SMSFactor\Connectors;
13
14
use IlGala\SMSFactor\Adapters\GuzzleHttpAdapter;
15
use GrahamCampbell\Manager\ConnectorInterface;
16
use InvalidArgumentException;
17
18
/**
19
 * @author Filippo Galante <[email protected]>
20
 */
21 View Code Duplication
class GuzzleHttpConnector implements ConnectorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
24
    /**
25
     * Establish an adapter connection.
26
     *
27
     * @param string[] $config
28
     *
29
     * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter
30
     */
31
    public function connect(array $config)
32
    {
33
        $config = $this->getConfig($config);
34
        return $this->getAdapter($config);
35
    }
36
37
    /**
38
     * Get the configuration.
39
     *
40
     * @param string[] $config
41
     *
42
     * @throws \InvalidArgumentException
43
     *
44
     * @return string[]
45
     */
46
    protected function getConfig(array $config)
47
    {
48
        if (!array_key_exists('username', $config) || !array_key_exists('password', $config) || !array_key_exists('accept', $config)) {
49
            throw new InvalidArgumentException('The guzzlehttp connector requires configuration.');
50
        }
51
        return array_only($config, ['username', 'password', 'accept']);
52
    }
53
54
    /**
55
     * Get the guzzlehttp adapter.
56
     *
57
     * @param string[] $config
58
     *
59
     * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter
60
     */
61
    protected function getAdapter(array $config)
62
    {
63
        return new GuzzleHttpAdapter($config['username'], $config['password'], $config['accept']);
64
    }
65
66
}
67