Completed
Pull Request — master (#78)
by butschster
14:38 queued 10:20
created

GitterClientServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 15
rs 9.4285
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @author butschster <[email protected]>
7
 * @date 09.04.2016 3:09
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace Core\Providers;
13
14
use Domains\BotManager;
15
use Domains\RoomManager;
16
use Gitter\Client;
17
use Illuminate\Container\Container;
18
use Illuminate\Support\ServiceProvider;
19
use Interfaces\Gitter\StandartGitterRoom;
20
use Interfaces\Slack\StandartSlackRoom;
21
22
/**
23
 * Class GitterClientServiceProvider
24
 * @package Core\Providers
25
 */
26
class GitterClientServiceProvider extends ServiceProvider
27
{
28
29
    public function register()
30
    {
31
        $this->app->singleton(Client::class, function (Container $app) {
32
            return new Client($app['config']->get('gitter.token'));
33
        });
34
35
        $this->app->singleton('bot', function (Container $app) {
36
            /** @var Client $client */
37
            $client = $app->make(Client::class);
38
            return $client->http->getCurrentUser()->wait();
39
        });
40
    }
41
42
    public function boot()
43
    {
44
        $this->app->singleton('bot.manager', function (Container $app) {
45
            return new BotManager($app);
0 ignored issues
show
Compatibility introduced by
$app of type object<Illuminate\Container\Container> is not a sub-type of object<Illuminate\Foundation\Application>. It seems like you assume a child class of the class Illuminate\Container\Container to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46
        });
47
48
        $this->app->singleton('room.manager', function (Container $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
            $manager = new RoomManager();
50
51
            $this->registerGitterRooms($manager);
52
            $this->registerSlackRooms($manager);
53
54
            return $manager;
55
        });
56
    }
57
58
    protected function registerGitterRooms(RoomManager $manager)
59
    {
60
        foreach ((array) $this->app['config']->get('gitter.rooms') as $room => $groups) {
61
            $manager->register(
62
                new StandartGitterRoom($room, $groups, \Config::get('gitter.middlewares'))
63
            );
64
        }
65
    }
66
67
    protected function registerSlackRooms(RoomManager $manager)
68
    {
69
        foreach ((array) $this->app['config']->get('slack.rooms') as $roomId => $groups) {
70
            $manager->register(
71
                new StandartSlackRoom($roomId, $groups, \Config::get('slack.middlewares'))
72
            );
73
        }
74
    }
75
}