eightball::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 15
Ratio 100 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 13
c 3
b 1
f 0
nc 1
nop 12
dl 15
loc 15
rs 9.4285

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Sovereign\Plugins\onMessage;
4
5
use Discord\Discord;
6
use Discord\Parts\Channel\Message;
7
use Monolog\Logger;
8
use Sovereign\Lib\Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Sovereign\Plugins\onMessage\Config.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use Sovereign\Lib\cURL;
10
use Sovereign\Lib\Db;
11
use Sovereign\Lib\Permissions;
12
use Sovereign\Lib\ServerConfig;
13
use Sovereign\Lib\Settings;
14
use Sovereign\Lib\Users;
15
16
class eightball extends \Threaded implements \Collectable
17
{
18
    /**
19
     * @var Message
20
     */
21
    private $message;
22
    /**
23
     * @var Discord
24
     */
25
    private $discord;
26
    /**
27
     * @var Logger
28
     */
29
    private $log;
30
    /**
31
     * @var array
32
     */
33
    private $channelConfig;
34
    /**
35
     * @var Config
36
     */
37
    private $config;
38
    /**
39
     * @var Db
40
     */
41
    private $db;
42
    /**
43
     * @var cURL
44
     */
45
    private $curl;
46
    /**
47
     * @var Settings
48
     */
49
    private $settings;
50
    /**
51
     * @var Permissions
52
     */
53
    private $permissions;
54
    /**
55
     * @var ServerConfig
56
     */
57
    private $serverConfig;
58
    /**
59
     * @var Users
60
     */
61
    private $users;
62
    /**
63
     * @var array
64
     */
65
    private $extras;
66
67 View Code Duplication
    public function __construct($message, $discord, $channelConfig, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
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...
68
    {
69
        $this->message = $message;
70
        $this->discord = $discord;
71
        $this->channelConfig = $channelConfig;
72
        $this->log = $log;
73
        $this->config = $config;
74
        $this->db = $db;
75
        $this->curl = $curl;
76
        $this->settings = $settings;
77
        $this->permissions = $permissions;
78
        $this->serverConfig = $serverConfig;
79
        $this->users = $users;
80
        $this->extras = $extras;
81
    }
82
83
    public function run()
84
    {
85
        $choices = array(
86
            'It is certain',
87
            'It is decidedly so',
88
            'Without a doubt',
89
            'Yes, definitely',
90
            'You may rely on it',
91
            'As I see it, yes',
92
            'Most likely',
93
            'More than likely',
94
            'Outlook good',
95
            'Yes',
96
            'No',
97
            'Lol no',
98
            'Signs point to, yes',
99
            'Reply hazy, try again',
100
            'Ask again later',
101
            'I Better not tell you now',
102
            'I Cannot predict now',
103
            'Concentrate and ask again',
104
            'Don\'t count on it',
105
            'My reply is no',
106
            'My sources say no',
107
            'Outlook not so good',
108
            'Very doubtful',
109
        );
110
111
        $this->message->reply($choices[array_rand($choices)]);
112
113
        // Mark this as garbage
114
        $this->isGarbage();
115
    }
116
}