Conditions | 8 |
Paths | 18 |
Total Lines | 58 |
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 |
||
60 | public function authLogin($data) |
||
61 | { |
||
62 | $data = $this->emptyValue($data); |
||
63 | |||
64 | $login = $data["login"]; |
||
65 | $password = $data["passLogin"]; |
||
66 | |||
67 | if (preg_match("/^.+[@]{1}.+$/", $login)) { |
||
68 | if (filter_var($login, FILTER_VALIDATE_EMAIL) == false) { |
||
69 | $this->onError("login", " *Enter correct Email address"); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if ($this->flag == 0) { |
||
74 | $password = md5($password); |
||
75 | $query = " |
||
76 | SELECT * FROM login WHERE email = '$login' or username = '$login' |
||
77 | "; |
||
78 | if ($result = $this->connect->query($query)) { |
||
79 | if ($result->num_rows > 0) { |
||
80 | |||
81 | $row = $result->fetch_assoc(); |
||
82 | $loginID = $row['login_id']; |
||
83 | $query = " |
||
84 | SELECT id FROM register WHERE |
||
85 | id = '$loginID' and |
||
86 | password = '$password' |
||
87 | "; |
||
88 | if ($result = $this->connect->query($query)) { |
||
89 | if ($result->num_rows > 0) { |
||
90 | Session::put('start', $loginID); |
||
91 | return json_encode( |
||
92 | [ |
||
93 | "location" => URL . "/account.php" |
||
94 | ] |
||
95 | ); |
||
96 | } |
||
97 | $this->onError("passLogin", " *Invalid password"); |
||
98 | return json_encode($this->error); |
||
99 | } |
||
100 | return json_encode( |
||
101 | [ |
||
102 | "Error" => "You are not registered, " . $this->connect->error |
||
103 | ] |
||
104 | ); |
||
105 | } |
||
106 | $this->onError("login", " *Invalid username or email"); |
||
107 | return json_encode($this->error); |
||
108 | } |
||
109 | return json_encode( |
||
110 | [ |
||
111 | "Error" => "You are not registered, " . $this->connect->error |
||
112 | ] |
||
113 | ); |
||
114 | } else { |
||
115 | return json_encode($this->error); |
||
116 | } |
||
117 | } |
||
118 | |||
165 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.