| Conditions | 11 |
| Paths | 46 |
| Total Lines | 45 |
| Code Lines | 28 |
| 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 |
||
| 13 | public function update($input) { |
||
| 14 | if(is_null($input)) return false; |
||
| 15 | if($this->isProtected()) return false; |
||
| 16 | |||
| 17 | $value = is_null($this->local) ? $this->default : $this->local; |
||
| 18 | if($value == $input) return false; |
||
| 19 | if($input === '') { |
||
| 20 | $this->local = $input; |
||
| 21 | return true; |
||
| 22 | } |
||
| 23 | $mail = $input; |
||
| 24 | |||
| 25 | if($this->placeholders) { |
||
| 26 | // replace variables with pseudo values |
||
| 27 | $mail = str_replace('@USER@', 'joe', $mail); |
||
| 28 | $mail = str_replace('@NAME@', 'Joe Schmoe', $mail); |
||
| 29 | $mail = str_replace('@MAIL@', '[email protected]', $mail); |
||
| 30 | } |
||
| 31 | |||
| 32 | // multiple mail addresses? |
||
| 33 | if($this->multiple) { |
||
| 34 | $mails = array_filter(array_map('trim', explode(',', $mail))); |
||
| 35 | } else { |
||
| 36 | $mails = array($mail); |
||
| 37 | } |
||
| 38 | |||
| 39 | // check them all |
||
| 40 | foreach($mails as $mail) { |
||
| 41 | // only check the address part |
||
| 42 | if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)) { |
||
| 43 | $addr = $matches[2]; |
||
| 44 | } else { |
||
| 45 | $addr = $mail; |
||
| 46 | } |
||
| 47 | |||
| 48 | if(!mail_isvalid($addr)) { |
||
| 49 | $this->error = true; |
||
| 50 | $this->input = $input; |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->local = $input; |
||
| 56 | return true; |
||
| 57 | } |
||
| 58 | } |
||
| 59 |