about::__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 DateTime;
6
use Discord\Discord;
7
use Discord\Parts\Channel\Message;
8
use Monolog\Logger;
9
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...
10
use Sovereign\Lib\cURL;
11
use Sovereign\Lib\Db;
12
use Sovereign\Lib\Permissions;
13
use Sovereign\Lib\ServerConfig;
14
use Sovereign\Lib\Settings;
15
use Sovereign\Lib\Users;
16
17
class about extends \Threaded implements \Collectable
18
{
19
    /**
20
     * @var Message
21
     */
22
    private $message;
23
    /**
24
     * @var Discord
25
     */
26
    private $discord;
27
    /**
28
     * @var Logger
29
     */
30
    private $log;
31
    /**
32
     * @var array
33
     */
34
    private $channelConfig;
35
    /**
36
     * @var Config
37
     */
38
    private $config;
39
    /**
40
     * @var Db
41
     */
42
    private $db;
43
    /**
44
     * @var cURL
45
     */
46
    private $curl;
47
    /**
48
     * @var Settings
49
     */
50
    private $settings;
51
    /**
52
     * @var Permissions
53
     */
54
    private $permissions;
55
    /**
56
     * @var ServerConfig
57
     */
58
    private $serverConfig;
59
    /**
60
     * @var Users
61
     */
62
    private $users;
63
    /**
64
     * @var array
65
     */
66
    private $extras;
67
68 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...
69
    {
70
        $this->message = $message;
71
        $this->discord = $discord;
72
        $this->channelConfig = $channelConfig;
73
        $this->log = $log;
74
        $this->config = $config;
75
        $this->db = $db;
76
        $this->curl = $curl;
77
        $this->settings = $settings;
78
        $this->permissions = $permissions;
79
        $this->serverConfig = $serverConfig;
80
        $this->users = $users;
81
        $this->extras = $extras;
82
    }
83
84
    public function run()
85
    {
86
        $time1 = new DateTime(date("Y-m-d H:i:s", $this->extras["startTime"]));
87
        $time2 = new DateTime(date("Y-m-d H:i:s"));
88
        $interval = $time1->diff($time2);
89
90
        $msg = "```I am the vanguard of your destruction. This exchange is just beginning...
91
92
Author: Karbowiak (Discord ID: 118440839776174081)
93
Library: DiscordPHP (https://github.com/teamreflex/DiscordPHP\)
94
Current Version: 0.0000000000
95
Github Repo: https://github.com/karbowiak/Sovereign\
96
97
Statistics:
98
Guild/Server Count: {$this->extras["guildCount"]} (For specifics use {$this->channelConfig->prefix}guilds)
99
Member Count: {$this->extras["memberCount"]}
100
Memory Usage: ~" . round(memory_get_usage() / 1024 / 1024, 3) . "MB
101
Uptime: " . $interval->y . " Year(s), " . $interval->m . " Month(s), " . $interval->d . " Days, " . $interval->h . " Hours, " . $interval->i . " Minutes, " . $interval->s . " seconds.
102
```";
103
        $this->message->reply($msg);
104
105
        // Mark this as garbage
106
        $this->isGarbage();
107
    }
108
}