ZendeskServiceProvider::register()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 1
nop 0
crap 6
1
<?php
2
3
namespace NotificationChannels\Zendesk;
4
5
use Zendesk\API\HttpClient;
6
use Illuminate\Support\ServiceProvider;
7
use NotificationChannels\Zendesk\Exceptions\InvalidConfiguration;
8
9
class ZendeskServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the application services.
13
     */
14
    public function register()
15
    {
16
        $this->app->when(ZendeskChannel::class)
17
            ->needs(HttpClient::class)
18
            ->give(function () {
19
                $config = config('services.zendesk');
20
                if (! isset($config['subdomin'], $config['username'], $config['token'])) {
21
                    throw InvalidConfiguration::configurationNotSet();
22
                }
23
24
                $client = new HttpClient($config['subdomin']);
25
                $client->setAuth('basic', ['username' => $config['username'], 'token' => $config['token']]);
26
27
                return $client;
28
            });
29
    }
30
}
31