Conditions | 1 |
Paths | 1 |
Total Lines | 52 |
Code Lines | 28 |
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 |
||
9 | public function index() |
||
|
|||
10 | { |
||
11 | $path = str_replace($_SERVER['DOCUMENT_ROOT'], '',str_replace('\\', '/', __FILE__)); |
||
12 | $baseUrl = str_replace('Http/Controllers/ApiDocumentController.php', '', $path); |
||
13 | $jsonDoc = json_decode(file_get_contents(app_path('Modules/V1/Core/Resources/api.json')), true); |
||
14 | $modules = $jsonDoc['modules']; |
||
15 | $errors = $jsonDoc['errors']; |
||
16 | $conditions = [ |
||
17 | [ |
||
18 | "title" => "email equal [email protected]:", |
||
19 | "content" => "{\n \"email\" =>\"[email protected]\"\n}" |
||
20 | ], |
||
21 | [ |
||
22 | "title" => "email equal [email protected] and user is blocked:", |
||
23 | "content" => "{\n \"and\":{\n \"email\" =>\"[email protected]\",\n \"blocked\" =>1\n }\n}" |
||
24 | ], |
||
25 | [ |
||
26 | "title" => "email equal [email protected] or user is blocked:", |
||
27 | "content" => "{\n \"or\":{\n \"email\" =>\"[email protected]\",\n \"blocked\" =>1\n {\n}" |
||
28 | ], |
||
29 | [ |
||
30 | "title" => "email contain John:", |
||
31 | "content" => "{\n \"email\" =>{\n \"op\" =>\"like\",\n \"val\" =>\"%John%\"\n }\n}" |
||
32 | ], |
||
33 | [ |
||
34 | "title" => "user created after 2016-10-25:", |
||
35 | "content" => "{\n \"created_at\" =>{\n \"op\" =>\">\",\n \"val\" =>\"2016-10-25\"\n }\n}" |
||
36 | ], |
||
37 | [ |
||
38 | "title" => "user created between 2016-10-20 and 2016-10-25:", |
||
39 | "content" => "{\n \"created_at\" =>{\n \"op\" =>\"between\",\n \"val1\" =>\"2016-10-20\",\n \"val2\" =>\"2016-10-25\"\n {\n}" |
||
40 | ], |
||
41 | [ |
||
42 | "title" => "user id in 1,2,3:", |
||
43 | "content" => "{\n \"id\" =>{\n \"op\" =>\"in\",\n \"val\" =>[1, 2, 3]\n}" |
||
44 | ], |
||
45 | [ |
||
46 | "title" => "user name is null:", |
||
47 | "content" => "{\n \"name\" =>{\n \"op\" =>\"null\"\n}" |
||
48 | ], |
||
49 | [ |
||
50 | "title" => "user name is not null:", |
||
51 | "content" => "{\n \"name\" =>{\n \"op\" =>\"not null\"\n}" |
||
52 | ], |
||
53 | [ |
||
54 | "title" => "user has group admin:", |
||
55 | "content" => "{\n \"groups\" =>{\n \"op\" =>\"has\",\n \"val\" =>{\n \t\"name\" =>\"Admin\"\n }\n}" |
||
56 | ] |
||
57 | ]; |
||
58 | |||
59 | return view('core::doc', ['baseUrl' => $baseUrl, 'modules' => $modules, 'errors' => $errors, 'conditions' => $conditions]); |
||
60 | } |
||
61 | |||
74 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: