ApiClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Crummy\Phlack\Bridge\Guzzle;
4
5
use Guzzle\Common\Collection;
6
use Guzzle\Common\Event;
7
use Guzzle\Service\Client;
8
use Guzzle\Service\Description\ServiceDescription;
9
10
class ApiClient extends Client
11
{
12
    /**
13
     * @param array $config
14
     */
15 3
    public function __construct($config = [])
16
    {
17 3
        $config = Collection::fromConfig($config, [], ['token']);
18 3
        parent::__construct('', $config);
19
20 3
        $description = ServiceDescription::factory(__DIR__.'/Resources/slack_api.json');
21 3
        $this->setDescription($description);
22
23 3
        $this->getEventDispatcher()->addListener('command.before_prepare', function (Event $event) use ($config) {
24 1
            $event['command']['token'] = $config['token'];
25 3
        });
26 3
    }
27
28
    /**
29
     * @param array $config
30
     *
31
     * @return ApiClient
32
     */
33 1
    public static function factory($config = [])
34
    {
35 1
        return new self($config);
36
    }
37
}
38