Passed
Push — master ( de53d8...b05c35 )
by Jhao
02:13
created

LaravelServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda)
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
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK;
15
16
use Psr\Log\LoggerAwareInterface;
17
use GuzzleHttp\Client as GuzzleClient;
18
use Illuminate\Support\ServiceProvider;
19
use Illuminate\Contracts\Container\Container;
20
use Appwilio\RussianPostSDK\Tracking\PacketAccessClient;
21
use Appwilio\RussianPostSDK\Tracking\SingleAccessClient;
22
use Appwilio\RussianPostSDK\Dispatching\DispatchingClient;
23
24
class LaravelServiceProvider extends ServiceProvider
25
{
26
    protected $defer = true;
27
28 1
    public function register()
29
    {
30
        $this->app->singleton(SingleAccessClient::class, static function (Container $app) {
31
            $config = $app['config']['services.russianpost.tracking'];
32
33
            return $this->setLoggerToClient(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setLoggerToClient..., $config['password'])) targeting Appwilio\RussianPostSDK\...er::setLoggerToClient() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
34
                new SingleAccessClient($config['login'], $config['password'])
35
            );
36 1
        });
37
38
        $this->app->singleton(PacketAccessClient::class, static function (Container $app) {
39
            $config = $app['config']['services.russianpost.tracking'];
40
41
            return $this->setLoggerToClient(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->setLoggerToClient..., $config['password'])) targeting Appwilio\RussianPostSDK\...er::setLoggerToClient() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
                new PacketAccessClient($config['login'], $config['password'])
43
            );
44 1
        });
45
46
        $this->app->singleton(DispatchingClient::class, static function (Container $app) {
47
            $config = $app['config']['services.russianpost.dispatching'];
48
49
            $client = new DispatchingClient(
50
                $config['login'], $config['password'], $config['token'], new GuzzleClient()
51
            );
52
53
            $this->setLoggerToClient($client);
54
55
            return $client;
56 1
        });
57 1
    }
58
59 1
    public function provides(): array
60
    {
61
        return [
62 1
            DispatchingClient::class,
63
            SingleAccessClient::class,
64
            PacketAccessClient::class,
65
        ];
66
    }
67
68
    private function setLoggerToClient(LoggerAwareInterface $client)
69
    {
70
        if ($this->app->bound('appwilio.russianpost.logger')) {
71
            $client->setLogger($this->app['appwilio.russianpost.logger']);
72
        }
73
    }
74
}
75