Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
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 |
||
11 | { |
||
12 | public function _before(ApiTester $I) |
||
|
|||
13 | { |
||
14 | $user = $I->grabEntityFromRepository(User::class, ['id' => 1]); |
||
15 | $I->haveInRepository(DbConfiguration::class, [ |
||
16 | 'owner' => $user, |
||
17 | 'title' => 'sqlite config', |
||
18 | 'url' => 'sqlite:///data/db/db.sqlite', |
||
19 | ]); |
||
20 | $I->haveInRepository(DbConfiguration::class, [ |
||
21 | 'owner' => $user, |
||
22 | 'title' => 'mysql config', |
||
23 | 'url' => 'mysql://test-user:test-pwd@mysql/test', |
||
24 | ]); |
||
25 | for ($i = 1; $i < 10; $i++) { |
||
26 | $I->haveInRepository(DbConfiguration::class, [ |
||
27 | 'owner' => $user, |
||
28 | 'title' => sprintf('project %d config', $i), |
||
29 | 'url' => 'sqlite:///data/db/db.sqlite', |
||
30 | ]); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | public function getAllConfigurations(ApiTester $I) |
||
35 | { |
||
36 | $I->wantTo('get all db configurations'); |
||
37 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
38 | $I->sendGET('/configs?l=100'); |
||
39 | $I->seeResponseCodeIs(HttpCode::OK); |
||
40 | $configs = [ |
||
41 | [ |
||
42 | 'title' => 'sqlite config', |
||
43 | ], |
||
44 | [ |
||
45 | 'title' => 'mysql config', |
||
46 | ], |
||
47 | ]; |
||
48 | $otherConfigs = []; |
||
49 | for ($i = 1; $i < 10; $i++) { |
||
50 | $otherConfigs[] = [ |
||
51 | 'title' => sprintf('project %d config', $i), |
||
52 | ]; |
||
53 | } |
||
54 | $configs = array_merge($configs, $otherConfigs); |
||
55 | $I->seeResponseContainsJson([ |
||
56 | 'success' => true, |
||
57 | 'data' => [ |
||
58 | 'configurations' => $configs, |
||
59 | 'count' => 11, |
||
60 | ] |
||
61 | ]); |
||
62 | } |
||
63 | |||
64 | public function getSecondPageConfigurations(ApiTester $I) |
||
65 | { |
||
66 | $I->wantTo('get second page of db configurations'); |
||
67 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
68 | $I->sendGET('/configs?p=2'); |
||
69 | $I->seeResponseCodeIs(HttpCode::OK); |
||
70 | $I->seeResponseContainsJson([ |
||
151 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.