Passed
Branch master (120d90)
by
unknown
02:31
created

getLog::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 6
rs 9.4285
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
/**
28
 * @property  message
29
 */
30
class getLog
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...
31
{
32
    /**
33
     * @var
34
     */
35
    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...
36
    /**
37
     * @var
38
     */
39
    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...
40
    /**
41
     * @var
42
     */
43
    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...
44
45
    public $message;
46
47
    /**
48
     * @param $config
49
     * @param $discord
50
     * @param $logger
51
     */
52
    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...
53
    {
54
        $this->config = $config;
55
        $this->discord = $discord;
56
        $this->logger = $logger;
57
    }
58
59
    /**
60
     *
61
     */
62
    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...
63
    {
64
    }
65
66
    /**
67
     * @param $msgData
68
     * @param $message
69
     * @return null
70
     */
71
    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...
72
    {
73
        $this->message = $message;
74
75
        $message = $msgData["message"]["message"];
76
77
        $data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]);
78
        if (isset($data["trigger"])) {
79
80
            //Admin Check
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
                    $logType = (string)$data["messageString"];
90
                    if ($logType == "log") {
91
                        $filePath = dirname(__FILE__) . "/../../../log/dramielLog.log";
92
                    } elseif ($logType == "error") {
93
                        $filePath = dirname(__FILE__) . "/../../../log/dramielError.log";
94
                    } elseif ($logType == "other") {
95
                        $filePath = dirname(__FILE__) . "/../../../log/dramielOther.log";
96
                    } else {
97
                        $msg = "Incorrect log selected. Use either log, error, other";
98
                        $this->message->reply($msg);
99
                        return null;
100
                    }
101
                    $logContents = tailCustom($filePath, 10);
102
103
                    $this->message->reply($logContents);
104
                    return null;
105
                }
106
            }
107
            $msg = ":bangbang: You do not have the necessary roles to issue this command :bangbang:";
108
            $this->message->reply($msg);
109
            return null;
110
        }
111
        return null;
112
    }
113
114
    /**
115
     * @return array
116
     */
117 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...
118
    {
119
        return array(
120
            "name" => "log",
121
            "trigger" => array($this->config["bot"]["trigger"] . "log"),
122
            "information" => "Get the end of log files. Follow command with either log, error, other **(Admin Role Required)**"
123
        );
124
    }
125
126
}
127