Test Setup Failed
Push — master ( bd93ea...b0fc14 )
by Bob
03:31
created

setNickname::onMessage()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 25
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 35
rs 8.5806
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
 * @property  message
28
 */
29
class setNickname
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
    /**
32
     * @var
33
     */
34
    var $config;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $config.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
35
    /**
36
     * @var
37
     */
38
    var $discord;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $discord.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
39
    /**
40
     * @var
41
     */
42
    var $logger;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $logger.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
43
44
    public $message;
45
46
    /**
47
     * @param $config
48
     * @param $discord
49
     * @param $logger
50
     */
51
    function init($config, $discord, $logger)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
52
    {
53
        $this->config = $config;
54
        $this->discord = $discord;
55
        $this->logger = $logger;
56
    }
57
58
    /**
59
     *
60
     */
61
    function tick()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
    {
63
    }
64
65
    /**
66
     * @param $msgData
67
     * @param $message
68
     * @return null
69
     */
70
    function onMessage($msgData, $message)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
    {
72
        $this->message = $message;
73
74
        $message = $msgData["message"]["message"];
75
76
        $data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]);
77
        if (isset($data["trigger"])) {
78
79
            //Admin Check
80
            $botID = $this->discord->id;
81
            $userID = $msgData["message"]["fromID"];
82
            $adminRoles = $this->config["bot"]["adminRoles"];
83
            $id = $this->config["bot"]["guild"];
84
            $guild = $this->discord->guilds->get('id', $id);
85
            $member = $guild->members->get("id", $userID);
86
            $roles = $member->roles;
87
            foreach ($roles as $role) {
88
                if (in_array($role->name, $adminRoles, true)) {
89
                    $member = $guild->members->get("id", $botID);
90
                    $nick = (string) $data["messageString"];
91
                    $member->setNickname($nick);
92
93
                    $msg = "Bot nickname changed to **{$nick}** by {$msgData["message"]["from"]}";
94
                    $this->logger->addInfo("Bot nickname changed to {$nick} by {$msgData["message"]["from"]}");
95
                    $this->message->reply($msg);
96
                    return null;
97
                }
98
            }
99
            $msg = ":bangbang: You do not have the necessary roles to issue this command :bangbang:";
100
            $this->message->reply($msg);
101
            return null;
102
        }
103
        return null;
104
    }
105
106
    /**
107
     * @return array
108
     */
109 View Code Duplication
    function information()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
110
    {
111
        return array(
112
            "name" => "nickname",
113
            "trigger" => array($this->config["bot"]["trigger"] . "nickname"),
114
            "information" => "Changes the bots nickname (Admin Role)"
115
        );
116
    }
117
118
    /**
119
     * @param $msgData
120
     * @param $message
121
     */
122
    function onMessageAdmin()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
    {
124
    }
125
126
}
127