Test Setup Failed
Pull Request — master (#42)
by Bob
03:13
created

price   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 159
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 1
A tick() 0 4 1
C onMessage() 0 90 9
A information() 0 8 1
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 priceChecks
28
 * @property  excludeChannel
29
 * @property  message
30
 */
31
class price
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...
32
{
33
    /**
34
     * @var
35
     */
36
    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...
37
    /**
38
     * @var
39
     */
40
    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...
41
    /**
42
     * @var
43
     */
44
    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...
45
    /**
46
     * @var
47
     */
48
    var $solarSystems;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $solarSystems.

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...
49
    /**
50
     * @var array
51
     */
52
    var $triggers = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $triggers.

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...
53
    public $excludeChannel;
54
    public $message;
55
56
    /**
57
     * @param $config
58
     * @param $discord
59
     * @param $logger
60
     */
61
    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...
62
    {
63
        $this->config = $config;
64
        $this->discord = $discord;
65
        $this->logger = $logger;
66
        $this->triggers[] = $this->config["bot"]["trigger"] . "pc";
67
        $this->triggers[] = $this->config["bot"]["trigger"] . strtolower("Jita");
68
        $this->triggers[] = $this->config["bot"]["trigger"] . strtolower("Amarr");
69
        $this->triggers[] = $this->config["bot"]["trigger"] . strtolower("Rens");
70
        $this->triggers[] = $this->config["bot"]["trigger"] . strtolower("Dodixie");
71
        $this->excludeChannel = $config["plugins"]["priceChecker"]["channelID"];
72
    }
73
74
    /**
75
     *
76
     */
77
    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...
78
    {
79
80
    }
81
82
    /**
83
     * @param $msgData
84
     * @param $message
85
     * @return null
86
     */
87
    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...
88
    {
89
        $this->message = $message;
90
        $user = $msgData["message"]["from"];
91
        $channelID = $msgData["message"]["channelID"];
92
93
94
        // Bind a few things to vars for the plugins
95
        $message = $msgData["message"]["message"];
96
97
        // Quick Lookups
98
        $quickLookUps = array(
99
            "plex" => array(
100
                "typeID" => 29668,
101
                "typeName" => "30 Day Pilot's License Extension (PLEX)"
102
            ),
103
            "30 day" => array(
104
                "typeID" => 29668,
105
                "typeName" => "30 Day Pilot's License Extension (PLEX)"
106
            )
107
        );
108
109
        $data = command(strtolower($message), $this->information()["trigger"], $this->config["bot"]["trigger"]);
110
111
        if (isset($data["trigger"])) {
112
113
            $systemName = $data["trigger"];
114
            $itemName = $data["messageString"];
115
            var_dump($itemName);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($itemName); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
116
            $single = apiTypeID(urlencode($itemName));
117
118
            // Quick lookups
119
            if (isset($quickLookUps[$itemName])) {
120
                $single = $quickLookUps[$itemName];
121
            }
122
123
            // Check if the channel is restricted
124
            if ($channelID == $this->excludeChannel) {
125
                return $this->message->reply("**Price Check not allowed in this channel**");
126
            }
127
128
            // If there is a single result, we'll get data now!
129
            if ($single) {
130
                $typeID = $single["typeID"];
131
132
                if (is_null($typeID)){
133
                    $typeID = $single;
134
                }
135
136
                if ($systemName == "pc"){
137
                    $solarSystemID = "global";
138
                } else {
139
                    $solarSystemID = apiCharacterID(urlencode($systemName));
140
                }
141
                var_dump($single[0]);
142
                var_dump($typeID);
143
                var_dump($solarSystemID);
144
145
                // Get pricing data
146
                if ($solarSystemID == "global") {
147
                    $data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?typeid={$typeID}"));
148
                } else {
149
                    $data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?usesystem={$solarSystemID}&typeid={$typeID}"));
150
                }
151
152
                $lowBuy = number_format((float) $data->marketstat->type->buy->min, 2);
153
                $avgBuy = number_format((float) $data->marketstat->type->buy->avg, 2);
154
                $highBuy = number_format((float) $data->marketstat->type->buy->max, 2);
155
                $lowSell = number_format((float) $data->marketstat->type->sell->min, 2);
156
                $avgSell = number_format((float) $data->marketstat->type->sell->avg, 2);
157
                $highSell = number_format((float) $data->marketstat->type->sell->max, 2);
158
159
                $this->logger->addInfo("Sending pricing info to {$user}");
160
                $solarSystemName = $systemName == "pc" ? "Global" : ucfirst($systemName);
161
                $messageData = "**System: {$solarSystemName}**
162
**Buy:**
163
   Low: {$lowBuy}
164
   Avg: {$avgBuy}
165
   High: {$highBuy}
166
**Sell:**
167
   Low: {$lowSell}
168
   Avg: {$avgSell}
169
   High: {$highSell}";
170
                $this->message->reply($messageData);
171
            } else {
172
                $this->message->reply("**Error:** ***{$itemName}*** not found");
173
            }
174
        }
175
        return null;
176
    }
177
178
    /**
179
     * @return array
180
     */
181
    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...
182
    {
183
        return array(
184
            "name" => "pc",
185
            "trigger" => $this->triggers,
186
            "information" => "Shows price information for items in EVE. To use simply type **!pc item_name** for global stats or **!jita/amarr/rens_or_dodixie item_name** for hub specific info."
187
        );
188
    }
189
}
190