jabberPingsTheCulture   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 7
Bugs 4 Features 1
Metric Value
c 7
b 4
f 1
dl 0
loc 94
rs 10
wmc 7
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B run() 0 36 6
1
<?php
2
3
namespace Sovereign\Plugins\onTimer;
4
5
use Discord\Discord;
6
use Discord\Parts\Channel\Channel;
7
use Monolog\Logger;
8
use Sovereign\Lib\Config;
9
use Sovereign\Lib\cURL;
10
use Sovereign\Lib\Db;
11
use Sovereign\Lib\Permissions;
12
use Sovereign\Lib\ServerConfig;
13
use Sovereign\Lib\Settings;
14
use Sovereign\Lib\Users;
15
16
class jabberPingsTheCulture extends \Threaded implements \Collectable
17
{
18
    /**
19
     * @var Discord
20
     */
21
    protected $discord;
22
    /**
23
     * @var Logger
24
     */
25
    protected $log;
26
    /**
27
     * @var Config
28
     */
29
    protected $config;
30
    /**
31
     * @var Db
32
     */
33
    protected $db;
34
    /**
35
     * @var cURL
36
     */
37
    protected $curl;
38
    /**
39
     * @var Settings
40
     */
41
    protected $settings;
42
    /**
43
     * @var Permissions
44
     */
45
    protected $permissions;
46
    /**
47
     * @var ServerConfig
48
     */
49
    protected $serverConfig;
50
    /**
51
     * @var Users
52
     */
53
    protected $users;
54
    /**
55
     * @var array
56
     */
57
    protected $extras;
58
59
    public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
60
    {
61
        $this->discord = $discord;
62
        $this->log = $log;
63
        $this->config = $config;
64
        $this->db = $db;
65
        $this->curl = $curl;
66
        $this->settings = $settings;
67
        $this->permissions = $permissions;
68
        $this->serverConfig = $serverConfig;
69
        $this->users = $users;
70
        $this->extras = $extras;
71
    }
72
73
    public function run()
74
    {
75
        $handle = fopen("/tmp/discord.db", "r+");
76
        flock($handle, LOCK_EX);
77
78
        $message = "";
79
        while ($row = fgets($handle)) {
80
            if (!empty($row)) {
81
                $row = str_replace("\n", "", str_replace("\r", "", str_replace("^@", "", $row)));
82
                if ($row == "" || $row == " ") {
83
                    continue;
84
                }
85
86
                $message .= $row . " | ";
87
            }
88
        }
89
90
        flock($handle, LOCK_UN);
91
        fclose($handle);
92
        $handle = fopen("/tmp/discord.db", "w+");
93
        fclose($handle);
94
        chmod("/tmp/discord.db", 0777);
95
        $data = null;
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
96
        $handle = null;
0 ignored issues
show
Unused Code introduced by
$handle is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
        clearstatcache();
98
99
        if (!empty($message)) {
100
            // Strip out the last |
101
            $message = trim(substr($message, 0, -2));
102
            $channelID = 154221481625124864;
103
            /** @var Channel $channel */
104
            $channel = Channel::find($channelID);
105
            $this->log->addInfo("Sending ping to #pings on The Culture");
106
            $channel->sendMessage("@everyone " . $message, false);
107
        }
108
    }
109
}
110