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

time::tick()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
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 time
28
 * @property  message
29
 */
30
class time
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
    public $config;
33
    public $discord;
34
    public $logger;
35
    public $message;
36
    private $excludeChannel;
37
38
    /**
39
     * @param $config
40
     * @param $discord
41
     * @param $logger
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
        $channelID = (int) $msgData['message']['channelID'];
59
60
        if (in_array($channelID, $this->excludeChannel, true))
61
        {
62
            return null;
63
        }
64
65
        $this->message = $message;
66
        $user = $msgData['message']['from'];
67
68
        $message = $msgData['message']['message'];
69
70
        $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']);
71
        if (isset($data['trigger'])) {
72
            $date = date('d-F-Y');
73
            $fullDate = date('Y-m-d H:i:s');
74
            $datetime = new DateTime($fullDate);
75
            $est = $datetime->setTimezone(new DateTimeZone('America/New_York'));
76
            $est = $est->format('H:i:s');
77
            $pst = $datetime->setTimezone(new DateTimeZone('America/Los_Angeles'));
78
            $pst = $pst->format('H:i:s');
79
            $utc = $datetime->setTimezone(new DateTimeZone('UTC'));
80
            $utc = $utc->format('H:i:s');
81
            $cet = $datetime->setTimezone(new DateTimeZone('Europe/Copenhagen'));
82
            $cet = $cet->format('H:i:s');
83
            $msk = $datetime->setTimezone(new DateTimeZone('Europe/Moscow'));
84
            $msk = $msk->format('H:i:s');
85
            $aus = $datetime->setTimezone(new DateTimeZone('Australia/Sydney'));
86
            $aus = $aus->format('H:i:s');
87
88
            $this->logger->addInfo("Time: Sending time info to {$user}");
89
            $this->message->reply("**EVE Time:** {$utc} -- **EVE Date:** {$date} -- **PST/Los Angeles:** {$pst} -- **EST/New York:** {$est} -- **CET/Copenhagen:** {$cet} -- **MSK/Moscow:** {$msk} -- **AEST/Sydney:** {$aus}");
90
        }
91
    }
92
93
    /**
94
     * @return array
95
     */
96 View Code Duplication
    public function information()
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...
97
    {
98
        return array(
99
            'name' => 'time',
100
            'trigger' => array($this->config['bot']['trigger'] . 'time'),
101
            'information' => 'This shows the time for various timezones compared to EVE Time. To use simply type <!time>'
102
        );
103
    }
104
}