| Conditions | 12 |
| Paths | 18 |
| Total Lines | 57 |
| 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 maskProperty(&$value, &$changed = null) |
||
| 49 | { |
||
| 50 | if (is_iterable($value)) { |
||
| 51 | foreach ($value as &$_value) { |
||
| 52 | $this->maskProperty($_value, $changed); |
||
| 53 | } |
||
| 54 | |||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | $initial_value = $value; |
||
| 59 | |||
| 60 | switch (gettype($this->cast($value))) { |
||
| 61 | case "boolean": |
||
| 62 | $value = $this->randomiseValueFromArray([true, false]); |
||
| 63 | |||
| 64 | break; |
||
| 65 | |||
| 66 | case "integer": |
||
| 67 | $value = $this->randomInteger(strlen($value)); |
||
| 68 | |||
| 69 | break; |
||
| 70 | |||
| 71 | case "double": |
||
| 72 | $value = $this->randomFloat(strlen($value)); |
||
| 73 | |||
| 74 | break; |
||
| 75 | |||
| 76 | case "string": |
||
| 77 | if (filter_var($value, FILTER_VALIDATE_EMAIL)) { |
||
| 78 | /*if (class_exists(\Faker\Factory::class)) { |
||
| 79 | $value = (\Faker\Factory::create())->safeEmail; |
||
| 80 | |||
| 81 | break; |
||
| 82 | }*/ |
||
| 83 | |||
| 84 | $value = strtolower($this->randomString(30)) . '@example.com'; |
||
| 85 | |||
| 86 | break; |
||
| 87 | } |
||
| 88 | |||
| 89 | $value = $this->randomString(strlen($value)); |
||
| 90 | |||
| 91 | break; |
||
| 92 | |||
| 93 | case "NULL": |
||
| 94 | case "unknown type": |
||
| 95 | $value = null; |
||
| 96 | |||
| 97 | break; |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 101 | if ($changed !== null && $initial_value !== $value) { |
||
| 102 | $changed = true; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 171 |