Conditions | 12 |
Paths | 12 |
Total Lines | 36 |
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 |
||
60 | private function checkAppleErrorResponse($fp) { |
||
61 | //byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID). Should return nothing if OK. |
||
62 | $apple_error_response = fread($fp, 6); |
||
63 | //NOTE: Make sure you set stream_set_blocking($fp, 0) or else fread will pause your script and wait forever when there is no response to be sent. |
||
64 | if ($apple_error_response) { |
||
65 | //unpack the error response (first byte 'command" should always be 8) |
||
66 | $error_response = unpack('Ccommand/Cstatus_code/Nidentifier', $apple_error_response); |
||
67 | if ($error_response['status_code'] == '0') { |
||
68 | $error_response['status_code'] = '0-No errors encountered'; |
||
69 | } else if ($error_response['status_code'] == '1') { |
||
70 | $error_response['status_code'] = '1-Processing error'; |
||
71 | } else if ($error_response['status_code'] == '2') { |
||
72 | $error_response['status_code'] = '2-Missing device token'; |
||
73 | } else if ($error_response['status_code'] == '3') { |
||
74 | $error_response['status_code'] = '3-Missing topic'; |
||
75 | } else if ($error_response['status_code'] == '4') { |
||
76 | $error_response['status_code'] = '4-Missing payload'; |
||
77 | } else if ($error_response['status_code'] == '5') { |
||
78 | $error_response['status_code'] = '5-Invalid token size'; |
||
79 | } else if ($error_response['status_code'] == '6') { |
||
80 | $error_response['status_code'] = '6-Invalid topic size'; |
||
81 | } else if ($error_response['status_code'] == '7') { |
||
82 | $error_response['status_code'] = '7-Invalid payload size'; |
||
83 | } else if ($error_response['status_code'] == '8') { |
||
84 | $error_response['status_code'] = '8-Invalid token'; |
||
85 | } else if ($error_response['status_code'] == '255') { |
||
86 | $error_response['status_code'] = '255-None (unknown)'; |
||
87 | } else { |
||
88 | $error_response['status_code'] = $error_response['status_code'] . '-Not listed'; |
||
89 | } |
||
90 | echo '<br><b>+ + + + + + ERROR</b> Response Command:<b>' . $error_response['command'] . '</b> Identifier:<b>' . $error_response['identifier'] . '</b> Status:<b>' . $error_response['status_code'] . '</b><br>'; |
||
91 | echo 'Identifier is the rowID (index) in the database that caused the problem, and Apple will disconnect you from server. To continue sending Push Notifications, just start at the next rowID after this Identifier.<br>'; |
||
92 | return true; |
||
93 | } |
||
94 | return false; |
||
95 | } |
||
96 | |||
98 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.