Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
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 |
||
85 | public function safeDefaultsMatchingProvider() : array |
||
86 | { |
||
87 | return [ |
||
88 | 'empty' => [ |
||
89 | '', |
||
90 | false, |
||
91 | ], |
||
92 | 'GET' => [ |
||
93 | 'GET', |
||
94 | true, |
||
95 | ], |
||
96 | 'get' => [ |
||
97 | 'get', |
||
98 | true, |
||
99 | ], |
||
100 | 'HEAD' => [ |
||
101 | 'HEAD', |
||
102 | true, |
||
103 | ], |
||
104 | 'head' => [ |
||
105 | 'head', |
||
106 | true, |
||
107 | ], |
||
108 | 'OPTIONS' => [ |
||
109 | 'OPTIONS', |
||
110 | true, |
||
111 | ], |
||
112 | 'options' => [ |
||
113 | 'options', |
||
114 | true, |
||
115 | ], |
||
116 | 'DELETE' => [ |
||
117 | 'DELETE', |
||
118 | false, |
||
119 | ], |
||
120 | 'delete' => [ |
||
121 | 'delete', |
||
122 | false, |
||
123 | ], |
||
124 | 'POST' => [ |
||
125 | 'POST', |
||
126 | false, |
||
127 | ], |
||
128 | 'post' => [ |
||
129 | 'post', |
||
130 | false, |
||
131 | ], |
||
132 | 'PUT' => [ |
||
133 | 'PUT', |
||
134 | false, |
||
135 | ], |
||
136 | 'put' => [ |
||
137 | 'put', |
||
138 | false, |
||
139 | ], |
||
140 | 'UNKNOWN' => [ |
||
141 | 'UNKNOWN', |
||
142 | false, |
||
143 | ], |
||
144 | 'unknown' => [ |
||
145 | 'unknown', |
||
146 | false, |
||
147 | ], |
||
148 | ]; |
||
149 | } |
||
150 | } |
||
151 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.