Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
61 | public function testReplace(): void |
||
62 | { |
||
63 | $GLOBALS['urlParams'] = []; |
||
64 | $_POST['db'] = $GLOBALS['db']; |
||
65 | $_POST['table'] = $GLOBALS['table']; |
||
66 | $_POST['ajax_request'] = 'true'; |
||
67 | $_POST['sql_query'] = ''; |
||
68 | $_POST['clause_is_unique'] = 1; |
||
69 | $_POST['where_clause'] = [ |
||
70 | '`test`.`ser` = 2', |
||
71 | '`test`.`ser` = 1', |
||
72 | ]; |
||
73 | $_POST['rel_fields_list'] = ''; |
||
74 | $_POST['do_transformations'] = true; |
||
75 | $_POST['transform_fields_list'] = '0%5Bvc%5D=sss%20s%20s&1%5Bvc%5D=zzff%20s%20sf%0A'; |
||
76 | $_POST['relational_display'] = 'K'; |
||
77 | $_POST['goto'] = 'index.php?route=/sql'; |
||
78 | $_POST['submit_type'] = 'save'; |
||
79 | $_POST['fields'] = [ |
||
80 | 'multi_edit' => [ |
||
81 | 0 => ['zzff s sf'], |
||
82 | 1 => ['sss s s'], |
||
83 | ], |
||
84 | ]; |
||
85 | $_POST['fields_name'] = [ |
||
86 | 'multi_edit' => [ |
||
87 | 0 => ['vc'], |
||
88 | 1 => ['vc'], |
||
89 | ], |
||
90 | ]; |
||
91 | $_POST['fields_null'] = [ |
||
92 | 'multi_edit' => [ |
||
93 | 0 => [], |
||
94 | 1 => [], |
||
95 | ], |
||
96 | ]; |
||
97 | |||
98 | $dummyDbi = $this->createDbiDummy(); |
||
99 | $dbi = $this->createDatabaseInterface($dummyDbi); |
||
100 | $relation = new Relation($dbi); |
||
101 | $transformations = new Transformations(); |
||
102 | $template = new Template(); |
||
103 | $response = new ResponseRenderer(); |
||
104 | $replaceController = new ReplaceController( |
||
105 | $response, |
||
106 | $template, |
||
107 | new InsertEdit($dbi, $relation, $transformations, new FileListing(), $template), |
||
108 | $transformations, |
||
109 | $relation, |
||
110 | $dbi |
||
111 | ); |
||
112 | |||
113 | $request = $this->createStub(ServerRequest::class); |
||
114 | $sqlController = new SqlController( |
||
115 | $response, |
||
116 | $template, |
||
117 | new Sql( |
||
118 | $dbi, |
||
119 | $relation, |
||
120 | new RelationCleanup($dbi, $relation), |
||
121 | new Operations($dbi, $relation), |
||
122 | $transformations, |
||
123 | $template |
||
124 | ), |
||
125 | new CheckUserPrivileges($dbi), |
||
126 | $dbi |
||
127 | ); |
||
128 | $GLOBALS['containerBuilder'] = $this->createStub(ContainerInterface::class); |
||
129 | $GLOBALS['containerBuilder']->method('get')->willReturn($sqlController); |
||
130 | |||
131 | $GLOBALS['goto'] = 'index.php?route=/sql'; |
||
132 | $dummyDbi->addSelectDb('my_db'); |
||
133 | $dummyDbi->addSelectDb('my_db'); |
||
134 | $replaceController($request); |
||
135 | $output = $response->getHTMLResult(); |
||
136 | $this->assertAllSelectsConsumed(); |
||
137 | $this->assertStringContainsString( |
||
138 | 'class="icon ic_s_success"> Showing rows 0 - 1 (2 total, Query took', |
||
139 | $output |
||
140 | ); |
||
141 | $this->assertStringContainsString('SELECT * FROM `test_tbl`', $output); |
||
142 | } |
||
198 |