| Conditions | 10 |
| Paths | 72 |
| Total Lines | 75 |
| Lines | 12 |
| Ratio | 16 % |
| 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 |
||
| 74 | public function authRegister($data) |
||
| 75 | { |
||
| 76 | $data = $this->emptyValue($data); |
||
| 77 | $name = $data["name"]; |
||
| 78 | $email = $data["email"]; |
||
| 79 | $username = $data["username"]; |
||
| 80 | $mob = $data["mob"]; |
||
| 81 | $password = $data["passRegister"]; |
||
| 82 | $userId = ''; |
||
| 83 | |||
| 84 | if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
||
| 85 | $this->onError("email", " *Enter correct Email address"); |
||
| 86 | } else if ($this->obValidate->validateEmailInDb($email) === 1) { |
||
| 87 | $this->onError("email", " *Email is already registered"); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($this->obValidate->validateUsernameInDb($username) === 1) { |
||
| 91 | $this->onError("username", " *Username is already registered"); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (!preg_match("/^[0-9]{10}$/", $data["mob"])) { |
||
| 95 | $this->onError("mob", " *Enter correct Mobile Number"); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($this->flag == 1) { |
||
| 99 | return json_encode($this->error); |
||
| 100 | } |
||
| 101 | |||
| 102 | $password = md5($password); |
||
| 103 | |||
| 104 | $query = "INSERT INTO register VALUES( |
||
| 105 | null, '$email', '$username', '$password' |
||
| 106 | )"; |
||
| 107 | View Code Duplication | if (!$this->connect->query($query)) { |
|
| 108 | return json_encode( |
||
| 109 | [ |
||
| 110 | "Error" => "You are not registered, ".$this->connect->error |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | $query = "SELECT id FROM register WHERE email = '$email'"; |
||
| 115 | if ($result = $this->connect->query($query)) { |
||
| 116 | $row = $result->fetch_assoc(); |
||
| 117 | $userId = $row['id']; |
||
| 118 | $query = "INSERT INTO login VALUES( |
||
| 119 | '$userId', '$name', '$email', '$username', '$mob', 0 |
||
| 120 | )"; |
||
| 121 | |||
| 122 | View Code Duplication | if (!$this->connect->query($query)) { |
|
| 123 | return json_encode( |
||
| 124 | [ |
||
| 125 | "Error" => "You are not registered, ".$this->connect->error |
||
| 126 | ] |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | $query = "INSERT INTO profile VALUES( |
||
| 131 | '$userId', 'Joined OpenChat', 'Joined OpenChat', '' |
||
| 132 | )"; |
||
| 133 | View Code Duplication | if (!$this->connect->query($query)) { |
|
| 134 | return json_encode( |
||
| 135 | [ |
||
| 136 | "Error" => "You are not registered, ".$this->connect->error |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | Session::put('start', $userId); |
||
| 142 | return json_encode( |
||
| 143 | [ |
||
| 144 | "location" => getenv('APP_URL')."/views/account.php" |
||
| 145 | ] |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 195 |
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.