time   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 91
Duplicated Lines 16.48 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 15
loc 91
rs 10
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 1
A run() 0 23 1

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
namespace Sovereign\Plugins\onMessage;
4
5
use DateTime;
6
use DateTimeZone;
7
use Discord\Discord;
8
use Discord\Parts\Channel\Message;
9
use Monolog\Logger;
10
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...
11
use Sovereign\Lib\cURL;
12
use Sovereign\Lib\Db;
13
use Sovereign\Lib\Permissions;
14
use Sovereign\Lib\ServerConfig;
15
use Sovereign\Lib\Settings;
16
use Sovereign\Lib\Users;
17
18
class time extends \Threaded implements \Collectable
19
{
20
    /**
21
     * @var Message
22
     */
23
    private $message;
24
    /**
25
     * @var Discord
26
     */
27
    private $discord;
28
    /**
29
     * @var Logger
30
     */
31
    private $log;
32
    /**
33
     * @var array
34
     */
35
    private $channelConfig;
36
    /**
37
     * @var Config
38
     */
39
    private $config;
40
    /**
41
     * @var Db
42
     */
43
    private $db;
44
    /**
45
     * @var cURL
46
     */
47
    private $curl;
48
    /**
49
     * @var Settings
50
     */
51
    private $settings;
52
    /**
53
     * @var Permissions
54
     */
55
    private $permissions;
56
    /**
57
     * @var ServerConfig
58
     */
59
    private $serverConfig;
60
    /**
61
     * @var Users
62
     */
63
    private $users;
64
    /**
65
     * @var array
66
     */
67
    private $extras;
68
69 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...
70
    {
71
        $this->message = $message;
72
        $this->discord = $discord;
73
        $this->channelConfig = $channelConfig;
74
        $this->log = $log;
75
        $this->config = $config;
76
        $this->db = $db;
77
        $this->curl = $curl;
78
        $this->settings = $settings;
79
        $this->permissions = $permissions;
80
        $this->serverConfig = $serverConfig;
81
        $this->users = $users;
82
        $this->extras = $extras;
83
    }
84
85
    public function run()
86
    {
87
        $date = date("d-m-Y");
88
        $fullDate = date("Y-m-d H:i:s");
89
        $dateTime = new DateTime($fullDate);
90
        $et = $dateTime->setTimezone(new DateTimeZone("America/New_York"));
91
        $et = $et->format("H:i:s");
92
        $pt = $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles"));
93
        $pt = $pt->format("H:i:s");
94
        $utc = $dateTime->setTimezone(new DateTimeZone("UTC"));
95
        $utc = $utc->format("H:i:s");
96
        $cet = $dateTime->setTimezone(new DateTimeZone("Europe/Copenhagen"));
97
        $cet = $cet->format("H:i:s");
98
        $msk = $dateTime->setTimezone(new DateTimeZone("Europe/Moscow"));
99
        $msk = $msk->format("H:i:s");
100
        $aest = $dateTime->setTimezone(new DateTimeZone("Australia/Sydney"));
101
        $aest = $aest->format("H:i:s");
102
        $msg = "**Current EVE Time:** {$utc} / **EVE Date:** {$date} / **Los Angeles (PT):** {$pt} / **New York (ET):** {$et} / **Berlin/Copenhagen (CET):** {$cet} / **Moscow (MSK):** {$msk} / **Sydney (AEST):** {$aest}";
103
        $this->message->reply($msg);
104
105
        // Mark this as garbage
106
        $this->isGarbage();
107
    }
108
}