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