| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| 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 |
||
| 43 | public function requestBodyProvider() |
||
| 44 | { |
||
| 45 | /** @noinspection PhpUnusedPrivateFieldInspection */ |
||
| 46 | return [ |
||
| 47 | 'null body' => [ |
||
| 48 | 'request parameter name', |
||
| 49 | null, |
||
| 50 | '', |
||
| 51 | ], |
||
| 52 | 'empty array' => [ |
||
| 53 | 'request parameter name', |
||
| 54 | [], |
||
| 55 | '', |
||
| 56 | ], |
||
| 57 | 'empty object' => [ |
||
| 58 | 'request parameter name', |
||
| 59 | (object) [], |
||
| 60 | '', |
||
| 61 | ], |
||
| 62 | 'array with matching parameter' => [ |
||
| 63 | 'request parameter name', |
||
| 64 | ['request parameter name' => 'foo'], |
||
| 65 | 'foo', |
||
| 66 | ], |
||
| 67 | 'array with matching non-string parameter' => [ |
||
| 68 | 'request parameter name', |
||
| 69 | ['request parameter name' => 123], |
||
| 70 | '', |
||
| 71 | ], |
||
| 72 | 'object with matching parameter' => [ |
||
| 73 | 'request parameter name', |
||
| 74 | (object) ['request parameter name' => 'foo'], |
||
| 75 | 'foo', |
||
| 76 | ], |
||
| 77 | 'object with matching non-string parameter' => [ |
||
| 78 | 'request parameter name', |
||
| 79 | (object) ['request parameter name' => 123], |
||
| 80 | '', |
||
| 81 | ], |
||
| 82 | 'class with private matching property' => [ |
||
| 83 | 'field', |
||
| 84 | new class { |
||
| 85 | private $field = 'bar'; |
||
| 86 | }, |
||
| 87 | '', |
||
| 88 | ], |
||
| 89 | 'class with protected matching property' => [ |
||
| 90 | 'field', |
||
| 91 | new class { |
||
| 92 | protected $field = 'bar'; |
||
| 93 | }, |
||
| 94 | '', |
||
| 95 | ], |
||
| 96 | 'class with public matching property' => [ |
||
| 97 | 'field', |
||
| 98 | new class { |
||
| 99 | public $field = 'bar'; |
||
| 100 | }, |
||
| 101 | 'bar', |
||
| 102 | ], |
||
| 103 | 'class with public matching non-string property' => [ |
||
| 104 | 'field', |
||
| 105 | new class { |
||
| 106 | public $field = 123; |
||
| 107 | }, |
||
| 108 | '', |
||
| 109 | ], |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | } |
||
| 113 |
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.