| Conditions | 20 |
| Paths | 37 |
| Total Lines | 82 |
| Code Lines | 43 |
| Lines | 24 |
| Ratio | 29.27 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 15 | public function checked($value = null, $oKey = null, $oName = null) { |
||
| 16 | |||
| 17 | if (is_null($value)) { |
||
| 18 | return $this->getChecked(); |
||
| 19 | } |
||
| 20 | |||
| 21 | //Checkboxy $this->value powinny mieć wyłącznie jako "string" |
||
| 22 | if (is_array($this->value)) { |
||
| 23 | $this->value = $this->value[0]; |
||
| 24 | } |
||
| 25 | |||
| 26 | $this->checked = false; |
||
| 27 | |||
| 28 | //Sprawdzamy typ przekazanych danych. |
||
| 29 | if (is_string($value)) { |
||
| 30 | $this->checked = $this->value == $value; |
||
| 31 | return $this; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (is_array($value)) { |
||
| 35 | if (isAssoc($value)) { |
||
| 36 | //W przypadku tablicy asocjacyjnej ($key=>$val) jeśli $val jest typu bool to znaczy że $key == $this->value |
||
| 37 | if (is_bool(array_values($value)[0])) { |
||
| 38 | if (array_key_exists($this->value, $value)) { |
||
| 39 | $this->checked = $value[$this->value]; |
||
| 40 | return $this; |
||
| 41 | } |
||
| 42 | } else { |
||
| 43 | //W przeciwnym przypdaku uznajemy że tablica przechowuje pary klucz => wartosc odpowiadające $this->name => $this->value |
||
| 44 | if (array_key_exists($this->name, $value)) { |
||
| 45 | $this->checked = $value[$this->name] == $this->value; |
||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | $this->checked = in_array($this->value, $value); |
||
| 51 | return $this; |
||
| 52 | } |
||
| 53 | |||
| 54 | return $this; |
||
| 55 | } |
||
| 56 | |||
| 57 | //Jeżeli jest obiektem to obowiązkowo należy podać drugi parametr jakim jest nazwa pola |
||
| 58 | if (is_object($value) && $oKey && $oName) { |
||
| 59 | foreach($value as $v) |
||
| 60 | { |
||
| 61 | View Code Duplication | if (property_exists($v, $oKey)) |
|
| 62 | { |
||
| 63 | $prop = $v->$oKey; |
||
| 64 | if (is_bool($prop)) |
||
| 65 | { |
||
| 66 | $this->checked = $prop; |
||
| 67 | } else |
||
| 68 | { |
||
| 69 | $this->checked = $prop == $this->value; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | return $this; |
||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | View Code Duplication | if (is_object($value) && $oKey) { |
|
| 78 | if (property_exists($value, $oKey)) |
||
| 79 | { |
||
| 80 | $prop = $value->$oKey; |
||
| 81 | if (is_bool($prop)) |
||
| 82 | { |
||
| 83 | $this->checked = $prop; |
||
| 84 | } else |
||
| 85 | { |
||
| 86 | $this->checked = $prop == $this->value; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if (is_bool($value)) { |
||
| 92 | $this->checked = $value; |
||
| 93 | return $this; |
||
| 94 | } |
||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | |||
| 128 | } |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.