Conditions | 14 |
Paths | 18 |
Total Lines | 49 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function tick() |
||
63 | { |
||
64 | if (filemtime($this->db) >= $this->lastCheck) { |
||
65 | $data = file($this->db); |
||
66 | if ($data) { |
||
67 | $ping = ''; |
||
68 | foreach ($data as $row) { |
||
69 | $row = str_replace('^@', '', $row); |
||
70 | if ($row == '' || $row == ' ') { |
||
71 | continue; |
||
72 | } |
||
73 | |||
74 | $ping .= $row . ' '; |
||
75 | } |
||
76 | |||
77 | // Remove | from the line or whatever else is at the last two characters in the string |
||
78 | $message = trim(substr($ping, 0, -2)); |
||
79 | foreach ($this->channelConfig as $chanName => $chanConfig) { |
||
80 | if ($chanConfig['searchString'] == false) { // If no match was found, and searchString is false, just use that |
||
81 | $message = $chanConfig['textStringPrepend'] . " \n " . $message . ' ' . $chanConfig['textStringAppend']; |
||
82 | $channelID = $chanConfig['channelID']; |
||
83 | } elseif (stristr($message, $chanConfig['searchString'])) { |
||
84 | $message = $chanConfig['textStringPrepend'] . " \n " . $message . ' ' . $chanConfig['textStringAppend']; |
||
85 | $channelID = $chanConfig['channelID']; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | if (!isset($channelID)) { // Make sure it's always set. |
||
90 | $channelID = null; |
||
91 | } |
||
92 | $begin = mb_substr($message, 0, 15); |
||
93 | if (strstr($begin, '#')) { |
||
94 | $message = 'skip'; |
||
95 | } |
||
96 | if ($channelID == '' || $channelID == null) { |
||
97 | $message = 'skip'; |
||
98 | } |
||
99 | if ($message != 'skip') { |
||
100 | $this->logger->addInfo("fileReader: Ping sent to front of queue for {$channelID}"); |
||
101 | priorityQueueMessage($message, $channelID, $this->guild); |
||
102 | } |
||
103 | } |
||
104 | $h = fopen($this->db, 'wb+'); |
||
105 | fclose($h); |
||
106 | chmod($this->db, 0777); |
||
107 | } |
||
108 | clearstatcache(); |
||
109 | $this->lastCheck = time(); |
||
110 | } |
||
111 | } |
||
112 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.