SlackServiceProvider::boot()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 14
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 25
ccs 0
cts 12
cp 0
crap 12
rs 9.7998
1
<?php declare(strict_types=1);
2
3
namespace DanielPieper\MergeReminder\ServiceProvider;
4
5
use DanielPieper\MergeReminder\Service\SlackService;
6
use DanielPieper\MergeReminder\SlackServiceAwareInterface;
7
use League\Container\Container;
8
use League\Container\ServiceProvider\AbstractServiceProvider;
9
use League\Container\ServiceProvider\BootableServiceProviderInterface;
10
use Razorpay\Slack\Client;
11
12
class SlackServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $provides = [
18
        Client::class,
19
        SlackService::class,
20
    ];
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function register()
26
    {
27
    }
28
29
    /**
30
     * Method will be invoked on registration of a service provider implementing
31
     * this interface. Provides ability for eager loading of Service Providers.
32
     *
33
     * @return void
34
     */
35
    public function boot()
36
    {
37
        /** @var Container $container */
38
        $container = $this->getContainer();
39
40
        if (!$container->get('SLACK_WEBHOOK_URL') || !$container->get('SLACK_CHANNEL')) {
41
            return;
42
        }
43
44
        $container->share(Client::class)
0 ignored issues
show
Bug introduced by
The method share() does not exist on League\Container\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $container->/** @scrutinizer ignore-call */ 
45
                    share(Client::class)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            ->addArguments([
46
                'SLACK_WEBHOOK_URL',
47
                [
48
                    'username' => 'Friendly Merge Reminder',
49
                    'icon' => ':owl:',
50
                    'channel' => $container->get('SLACK_CHANNEL'),
51
                    'allow_markdown' => true,
52
                ],
53
            ]);
54
55
        $container->share(SlackService::class)
56
            ->addArgument(Client::class);
57
58
        $container->inflector(SlackServiceAwareInterface::class)
59
            ->invokeMethod('setSlackService', [SlackService::class]);
60
    }
61
}
62