GitterClientServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 24
loc 64
rs 10
wmc 8
lcom 1
cbo 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 1
A boot() 0 15 1
A registerGitterRooms() 12 12 3
A registerSlackRooms() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    /**
59
     * @param RoomManager $manager
60
     */
61 View Code Duplication
    protected function registerGitterRooms(RoomManager $manager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        foreach ((array) $this->app['config']->get('gitter.rooms') as $room => $groups) {
64
            if (empty($room)) {
65
                continue;
66
            }
67
68
            $manager->register(
69
                new StandartGitterRoom($room, $groups, \Config::get('gitter.middlewares'))
70
            );
71
        }
72
    }
73
74
    /**
75
     * @param RoomManager $manager
76
     */
77 View Code Duplication
    protected function registerSlackRooms(RoomManager $manager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        foreach ((array) $this->app['config']->get('slack.rooms') as $roomId => $groups) {
80
            if (empty($roomId)) {
81
                continue;
82
            }
83
84
            $manager->register(
85
                new StandartSlackRoom($roomId, $groups, \Config::get('slack.middlewares'))
86
            );
87
        }
88
    }
89
}