Conditions | 15 |
Paths | 1008 |
Total Lines | 80 |
Code Lines | 61 |
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 |
||
48 | public function signup($username, $email, $password, $params) |
||
49 | { |
||
50 | $rules = [ |
||
51 | 'username' => ['required' => true], |
||
52 | 'email' => ['required' => true, 'email' => true], |
||
53 | 'password' => ['required' => true], |
||
54 | ]; |
||
55 | $inputs = [ |
||
56 | 'username' => $username, |
||
57 | 'email' => $email, |
||
58 | 'password' => $password, |
||
59 | ]; |
||
60 | $requireValidate = new Validation($inputs, $rules); |
||
61 | if ($requireValidate->fail()) { |
||
62 | Error::set($requireValidate->error()->get()); |
||
63 | } |
||
64 | $uniqueUsername = new Validation(['field'=> 'username', 'value'=>$username], __config()->auth->db_table, 'database'); |
||
|
|||
65 | if ($uniqueUsername->fail()) { |
||
66 | Error::set($uniqueUsername->error()->get()); |
||
67 | } |
||
68 | $uniqueEmail = new Validation(['field'=> 'email', 'value'=>$email], __config()->auth->db_table, 'database'); |
||
69 | if ($uniqueEmail->fail()) { |
||
70 | Error::set($uniqueEmail->error()->get()); |
||
71 | } |
||
72 | if (is_array($params)) { |
||
73 | foreach (array_keys($params) as $key => $value) { |
||
74 | $paramsRules = [$value => ['required' => true]]; |
||
75 | } |
||
76 | $paramsValidate = new Validation($params, $paramsRules); |
||
77 | if ($paramsValidate->fail()) { |
||
78 | Error::set($paramsValidate->error()->get()); |
||
79 | } |
||
80 | if (isset($params['passConfirm'])) { |
||
81 | if ($password !== $params['passConfirm']) { |
||
82 | Error::set(__printl('auth:error:password:confirm'), 'password'); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | if (__config()->auth->sticky_password) { |
||
87 | if (!(new PasswordManipulation())->isValid($password)) { |
||
88 | Error::set(__printl('auth:error:password:sticky'), 'password'); |
||
89 | } |
||
90 | } |
||
91 | if (!(new User())->isLogin()) { |
||
92 | if ($this->fail() !== true) { |
||
93 | $salts = (new Site())::salts(12); |
||
94 | $password_hash = Hash::make($password); |
||
95 | if (__config()->auth->is_verify_email) { |
||
96 | $token = (new Site())::salts(8); |
||
97 | } else { |
||
98 | $token = 'NULL'; |
||
99 | } |
||
100 | $param = [ |
||
101 | 'username' => $username, |
||
102 | 'email' => $email, |
||
103 | 'password' => $password_hash, |
||
104 | 'salts' => $salts, |
||
105 | 'token' => $token, |
||
106 | ]; |
||
107 | $fields = [ |
||
108 | 'db_name' => __config()->auth->db_name, |
||
109 | 'table' => __config()->auth->db_table, |
||
110 | ]; |
||
111 | unset($params['passConfirm']); |
||
112 | $data = ['columns' => array_merge($param, $params)]; |
||
113 | $values = array_merge($fields, $data); |
||
114 | $db = new DB(); |
||
115 | Success::set($db->db()->insert($values)); |
||
116 | $db->db()->close(); |
||
117 | if (__config()->auth->is_verify_email === true) { |
||
118 | $subject = __printl('auth:subject:need:verify'); |
||
119 | $link = site_base_url().__config()->auth->verification_link.'/'.$token; |
||
120 | $html = __printl('auth:body:need:verify'); |
||
121 | $html = str_replace(':email', $email, $html); |
||
122 | $html = str_replace(':link', $link, $html); |
||
123 | new EmailHandler($subject, $html, $email); |
||
124 | } |
||
125 | } |
||
126 | } else { |
||
127 | Error::set(__printl('auth:error:already:login'), 'login'); |
||
128 | } |
||
131 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.