Passed
Branch dev (745ef0)
by
unknown
03:03
created

about::tick()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Robert Sardinia
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
/**
27
 * Class about
28
 */
29
class about
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{
31
    public $config;
32
    public $discord;
33
    public $logger;
34
    public $message;
35
    private $excludeChannel;
36
37
    /**
38
     * @param $config
39
     * @param $discord
40
     * @param $logger
41
     * @internal param $message
42
     */
43 View Code Duplication
    public function init($config, $discord, $logger)
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...
44
    {
45
        $this->config = $config;
46
        $this->discord = $discord;
47
        $this->logger = $logger;
48
        $this->excludeChannel = $this->config['bot']['restrictedChannels'];
49
    }
50
51
    /**
52
     * @param $msgData
53
     * @param $message
54
     * @return null
55
     */
56
    public function onMessage($msgData, $message)
57
    {
58
        $this->message = $message;
59
        $info['guilds'] = $this->discord->guilds->count();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$info was never initialized. Although not strictly required by PHP, it is generally a good practice to add $info = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
60
        $channelID = (int) $msgData['message']['channelID'];
61
62
        if (in_array($channelID, $this->excludeChannel, true))
63
        {
64
            return null;
65
        }
66
67
        global $startTime; // Get the starttime of the bot
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
68
        $time1 = new DateTime(date('Y-m-d H:i:s', $startTime));
69
        $time2 = new DateTime(date('Y-m-d H:i:s'));
70
        $interval = $time1->diff($time2);
71
72
        $botID = $this->discord->id;
73
74
        $message = $msgData['message']['message'];
75
        $user = $msgData['message']['from'];
76
77
        $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']);
78
        if (isset($data['trigger'])) {
79
            $gitRevision = gitRevision();
80
            $gitBranch = gitBranch();
81
            $msg = '```
82
Developer: Shibdib (In-game Name: Mr Twinkie)
83
84
Bot ID: ' . $botID . '
85
86
Current Version: ' . $gitRevision['short'] . '
87
Current Branch: ' . $gitBranch . "
88
Github Repo: https://github.com/shibdib/Dramiel
89
90
Statistics:
91
Currently on {$info['guilds']} different discord servers.
92
Up-time: " . $interval->y . ' Year(s), ' . $interval->m . ' Month(s), ' . $interval->d . ' Days, ' . $interval->h . ' Hours, ' . $interval->i . ' Minutes, ' . $interval->s . ' seconds.
93
Memory Usage: ~' . round(memory_get_usage() / 1024 / 1024, 3) . 'MB```';
94
            $this->logger->addInfo("About: Sending about info to {$user}");
95
            $this->message->reply($msg);
96
        }
97
    }
98
99
    /**
100
     * @return array
101
     */
102
    public function information()
103
    {
104
        return array(
105
            'name' => 'about',
106
            'trigger' => array($this->config['bot']['trigger'] . 'about'),
107
            'information' => "Shows information on the bot, who created it, what library it's using, revision, and other stats. Example: !about"
108
        );
109
    }
110
}
111