Completed
Push — master ( ef103c...6c4a7c )
by Daniel
02:22
created

SlackServiceProvider::boot()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 6.28

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 2
nop 0
dl 0
loc 25
ccs 4
cts 14
cp 0.2857
crap 6.28
rs 9.7998
c 0
b 0
f 0
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 1
    public function boot()
36
    {
37
        /** @var Container $container */
38 1
        $container = $this->getContainer();
39
40 1
        if (!$container->get('SLACK_WEBHOOK_URL') || !$container->get('SLACK_CHANNEL')) {
41 1
            return;
42
        }
43
44
        $container->share(Client::class)
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