Passed
Push — master ( 6f6e1e...6553d9 )
by Mauro
01:35
created

Client::getChannels()   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
namespace MauroMoreno\DataFactory;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
7
/**
8
 * Class Client
9
 *
10
 * @package MauroMoreno\DataFactory
11
 */
12
class Client
13
{
14
15
    // URL Datafactory.la
16
    const BASE_URI = 'http://feed.datafactory.la';
17
18
    /**
19
     * @var \GuzzleHttp\Client
20
     */
21
    private $guzzleClient;
22
23
    /**
24
     * Client constructor.
25
     *
26
     * @param array $config
27
     */
28 4
    public function __construct(array $config = [])
29
    {
30 4
        $defaults['base_uri'] = self::BASE_URI;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$defaults was never initialized. Although not strictly required by PHP, it is generally a good practice to add $defaults = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
31 4
        $config = array_merge($defaults, $config);
32 4
        $this->guzzleClient = new GuzzleClient($config);
33 4
    }
34
35
    /**
36
     * Get Channels
37
     *
38
     * @return \Psr\Http\Message\ResponseInterface
39
     */
40 1
    public function getChannels()
41
    {
42 1
        return $this->getGuzzleClient()->get('/');
43
    }
44
45
    /**
46
     * Get Channel
47
     *
48
     * @param string $channel
49
     *
50
     * @return \Psr\Http\Message\ResponseInterface
51
     */
52 2
    public function getChannel(string $channel)
53
    {
54
        $params = [
55 2
            'canal' => $channel
56
        ];
57 2
        return $this->getGuzzleClient()->get('/', ['query' => $params]);
58
    }
59
60
    /**
61
     * Get Guzzle Client
62
     *
63
     * @return \GuzzleHttp\Client
64
     */
65 4
    public function getGuzzleClient()
66
    {
67 4
        return $this->guzzleClient;
68
    }
69
70
}
71