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

SlackServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 48
ccs 4
cts 16
cp 0.25
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 2 1
A boot() 0 25 3
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