GuzzleHttpConnector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 45
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 5 5 1
A getConfig() 7 7 4
A getAdapter() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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