| Conditions | 1 |
| Paths | 1 |
| Total Lines | 157 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 12 | public function samples(): array |
||
| 13 | { |
||
| 14 | return [ |
||
| 15 | new Sample('Basic usage', '', [new CodeSample( |
||
| 16 | __DIR__ . '/basic/basic.php', |
||
| 17 | [ |
||
| 18 | new IOSample( |
||
| 19 | '/api/users?search=Harry&status=1,2,3&desc=created_at&per_page=10', |
||
| 20 | 'select * from "users" where ("name" like "%Harry%") and "status" in ("1", "2", "3") order by "created_at" desc limit 11 offset 0' |
||
| 21 | ), |
||
| 22 | ] |
||
| 23 | ), |
||
| 24 | ]), |
||
| 25 | |||
| 26 | new Sample( |
||
| 27 | 'Search', |
||
| 28 | '', |
||
| 29 | [new CodeSample( |
||
| 30 | __DIR__ . '/search/search.php', |
||
| 31 | [ |
||
| 32 | new IOSample( |
||
| 33 | '/api/users?search=Harry', |
||
| 34 | 'select * from "users" where ("name" like "%Harry%" or "email" like "%Harry%") limit 16 offset 0' |
||
| 35 | ), |
||
| 36 | ] |
||
| 37 | ), |
||
| 38 | ] |
||
| 39 | ), |
||
| 40 | |||
| 41 | (new Sample( |
||
| 42 | 'Search', |
||
| 43 | 'Composite search', |
||
| 44 | [new CodeSample( |
||
| 45 | __DIR__ . '/search/composite_search.php', |
||
| 46 | [ |
||
| 47 | new IOSample( |
||
| 48 | '/api/users?search=2021', |
||
| 49 | 'select * from "users" where ("number" like "%2021%" or ("id" = "2021")) limit 16 offset 0' |
||
| 50 | ), |
||
| 51 | ] |
||
| 52 | ), |
||
| 53 | ] |
||
| 54 | ))->description('⚠️ The filter with default value is not supported yet.'), |
||
| 55 | new Sample( |
||
| 56 | 'Filter', |
||
| 57 | '', |
||
| 58 | [ |
||
| 59 | new CodeSample( |
||
| 60 | __DIR__ . '/filter/filter_column_contains_property_value.php', |
||
| 61 | [ |
||
| 62 | new IOSample( |
||
| 63 | '/api/users?name=Harry', |
||
| 64 | 'select * from "users" where "name" like "%Harry%" limit 16 offset 0' |
||
| 65 | ), |
||
| 66 | ] |
||
| 67 | ), |
||
| 68 | new CodeSample( |
||
| 69 | __DIR__ . '/filter/filter_column_equals_to_property_value.php', |
||
| 70 | [ |
||
| 71 | new IOSample( |
||
| 72 | '/api/users?status=1,2,3', |
||
| 73 | 'select * from "users" where "status" in ("1", "2", "3") limit 16 offset 0' |
||
| 74 | ), |
||
| 75 | ] |
||
| 76 | ), |
||
| 77 | new CodeSample( |
||
| 78 | __DIR__ . '/filter/filter_with_scope_and_default.php', |
||
| 79 | [ |
||
| 80 | new IOSample( |
||
| 81 | '/api/users?visible=1', |
||
| 82 | 'select * from "users" where "is_visible" = true limit 16 offset 0' |
||
| 83 | ), |
||
| 84 | new IOSample( |
||
| 85 | '/api/users', |
||
| 86 | 'select * from "users" where "is_visible" = true limit 16 offset 0' |
||
| 87 | ), |
||
| 88 | ] |
||
| 89 | ), |
||
| 90 | ] |
||
| 91 | ), |
||
| 92 | (new Sample( |
||
| 93 | 'Filter', |
||
| 94 | 'Typed filter', |
||
| 95 | [ |
||
| 96 | new CodeSample( |
||
| 97 | __DIR__ . '/filter/filter_orders_with_type_and_value.php', |
||
| 98 | [ |
||
| 99 | new IOSample( |
||
| 100 | '/api/users?search_type=number&search_value=2021', |
||
| 101 | 'select * from "orders" where "number" like "%2021%" limit 16 offset 0' |
||
| 102 | ), |
||
| 103 | ] |
||
| 104 | ), |
||
| 105 | ] |
||
| 106 | ))->description('⚠️ The filter with default value is not supported yet.'), |
||
| 107 | (new Sample( |
||
| 108 | 'Filter', |
||
| 109 | 'Flagged filter', |
||
| 110 | [ |
||
| 111 | new CodeSample( |
||
| 112 | __DIR__ . '/filter/filter_orders_match_any_filters.php', |
||
| 113 | [ |
||
| 114 | new IOSample( |
||
| 115 | '/api/users?number=2021&user_name=Jone', |
||
| 116 | 'select * from "orders" where (("number" like "%2021%") or (exists (select * from "users" where "orders"."user_id" = "users"."id" and "users"."name" like "%Jone%"))) limit 16 offset 0' |
||
| 117 | ), |
||
| 118 | ] |
||
| 119 | ), |
||
| 120 | ] |
||
| 121 | )), |
||
| 122 | new Sample( |
||
| 123 | 'Filter', |
||
| 124 | 'Cast Input(Skip auto cast)', |
||
| 125 | [ |
||
| 126 | new CodeSample( |
||
| 127 | __DIR__ . '/filter/cast_value_to_boolean.php', |
||
| 128 | [ |
||
| 129 | new IOSample( |
||
| 130 | '/api/users?is_visible=true', |
||
| 131 | 'select * from "users" where "is_visible" = true limit 16 offset 0' |
||
| 132 | ), |
||
| 133 | ] |
||
| 134 | ), |
||
| 135 | new CodeSample( |
||
| 136 | __DIR__ . '/filter/cast_value_force_to_string.php', |
||
| 137 | [ |
||
| 138 | new IOSample( |
||
| 139 | '/api/orders?content=code,and', |
||
| 140 | 'select * from "orders" where "content" like "%code,and%" limit 16 offset 0' |
||
| 141 | ), |
||
| 142 | ] |
||
| 143 | ), |
||
| 144 | ] |
||
| 145 | ), |
||
| 146 | new Sample( |
||
| 147 | 'Sort', |
||
| 148 | '', |
||
| 149 | [ |
||
| 150 | new CodeSample(__DIR__ . '/sort/sort_users_by_created_date.php', [ |
||
| 151 | new IOSample( |
||
| 152 | '/api/users?desc=created_date', |
||
| 153 | 'select * from "orders" order by "created_at" desc limit 16 offset 0' |
||
| 154 | ), |
||
| 155 | ]), |
||
| 156 | ] |
||
| 157 | ), |
||
| 158 | new Sample( |
||
| 159 | 'Paginator', |
||
| 160 | '', |
||
| 161 | [ |
||
| 162 | new CodeSample( |
||
| 163 | __DIR__ . '/paginator/paginate_by_size_per_page.php', |
||
| 164 | [new IOSample('/api/users?size=5', 'select * from "users" limit 6 offset 0')] |
||
| 165 | ), |
||
| 166 | new CodeSample( |
||
| 167 | __DIR__ . '/paginator/paginate_by_size_per_page_with_default.php', |
||
| 168 | [new IOSample('/api/users?size=', 'select * from "users" limit 6 offset 0')] |
||
| 169 | ), |
||
| 175 |