| Conditions | 7 | 
| Paths | 9 | 
| Total Lines | 69 | 
| 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 | ||
| 67 | public function replyTo($msg) | ||
| 68 |     { | ||
| 69 |         if (!empty($msg)) { | ||
| 70 | // checks for the value send | ||
| 71 | $userId = $msg->userId; | ||
| 72 | // stores id of the person whom message is to be sent | ||
| 73 | $receiverID = $msg->name; | ||
| 74 | $identifier; | ||
| 75 | |||
| 76 |             if ($receiverID > $userId) { | ||
| 77 | // geneate specific unique code to store messages | ||
| 78 | $user1 = $userId; | ||
| 79 | $user2 = $receiverID; | ||
| 80 | $identifier = $userId.":".$receiverID; | ||
| 81 |             } else { | ||
| 82 | $user1 = $receiverID; | ||
| 83 | $user2 = $userId; | ||
| 84 | $identifier = $receiverID.":".$userId; | ||
| 85 | } | ||
| 86 | |||
| 87 | // stores the message sent by the user. | ||
| 88 | $reply = addslashes(trim($msg->reply)); | ||
| 89 | // current time | ||
| 90 |             $time = date("D d M Y H:i:s"); | ||
| 91 | // echo $time; | ||
| 92 | // to sort the array on the basis of time | ||
| 93 |             $time_id = date("YmdHis"); | ||
| 94 | |||
| 95 | // the sender id must not be equal to current session id | ||
| 96 |             if ($reply != "" && $receiverID != $userId) { | ||
| 97 | // check whether the receiver is authorized or registered | ||
| 98 | $query = "SELECT * from login where login_id = '$receiverID'"; | ||
| 99 | |||
| 100 | $result = $this->connect->query($query); | ||
| 101 |                 if ($result->num_rows > 0) { | ||
| 102 | // check whether he is sending message | ||
| 103 | // for the first time or he has sent messages before | ||
| 104 | $query = "SELECT * from total_message where | ||
| 105 | identifier = '$identifier'"; | ||
| 106 | $result = $this->connect->query($query); | ||
| 107 |                     if ($result->num_rows > 0) { | ||
| 108 | // if he has sent messages before Update Total_Message Table | ||
| 109 | $query = "UPDATE total_message SET | ||
| 110 | total_messages = total_messages + 1, | ||
| 111 | time = '$time', unread = 1, | ||
| 112 | id = '$time_id' WHERE identifier = '$identifier'"; | ||
| 113 | |||
| 114 | return $this->updateMessages( | ||
| 115 | $query, $identifier, $reply, $userId, $time | ||
| 116 | ); | ||
| 117 | |||
| 118 |                     } else { | ||
| 119 | // if he sends message for the first time | ||
| 120 | // insert Details in Total_Message Table | ||
| 121 | $query = "INSERT into total_message values( | ||
| 122 | '$identifier', 1, '$user1', '$user2', 1, | ||
| 123 | '$time', '$time_id' | ||
| 124 | )"; | ||
| 125 | return $this->updateMessages( | ||
| 126 | $query, $identifier, $reply, $userId, $time | ||
| 127 | ); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | // if he is unauthorized echo message is failed | ||
| 131 | return "Invalid Authentication"; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | return "Failed"; | ||
| 135 | } | ||
| 136 | |||
| 166 | 
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.