Conditions | 3 |
Paths | 3 |
Total Lines | 53 |
Code Lines | 40 |
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 |
||
67 | public function testSaveFromGithub(): void |
||
68 | { |
||
69 | $i = 0; |
||
70 | while (1) { |
||
71 | try { |
||
72 | $i++; |
||
73 | $savedDeveloper = $this->Developers->get($i); |
||
74 | } catch (RecordNotFoundException $e) { |
||
75 | break; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | $nextId = $i; |
||
80 | |||
81 | $githubInfo = [ |
||
82 | 'login' => 'pma-bot', |
||
83 | 'id' => 1231231, |
||
84 | 'gravatar_id' => '', |
||
85 | 'url' => 'https://api.github.com/users/pma-bot', |
||
86 | 'name' => 'PMA BOT', |
||
87 | 'email' => '[email protected]', |
||
88 | 'has_commit_access' => 0, |
||
89 | ]; |
||
90 | $developer = $this->Developers->newEmptyEntity(); |
||
91 | $access_token = 'abc'; |
||
92 | |||
93 | $this->Developers->saveFromGithub($githubInfo, $access_token, $developer); |
||
94 | |||
95 | $savedDeveloper = $this->Developers->get($nextId); |
||
96 | $this->assertNotEquals(null, $savedDeveloper); |
||
97 | $this->assertEquals(1231231, $savedDeveloper->github_id); |
||
98 | $this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
||
99 | $this->assertEquals('[email protected]', $savedDeveloper->email); |
||
100 | $this->assertEquals(false, $savedDeveloper->has_commit_access); |
||
101 | |||
102 | $updatedGithubInfo = [ |
||
103 | 'login' => 'pma-bot', |
||
104 | 'id' => 1231231, |
||
105 | 'gravatar_id' => '', |
||
106 | 'url' => 'https://api.github.com/users/pma-bot', |
||
107 | 'name' => 'PMA BOT', |
||
108 | 'email' => '[email protected]', |
||
109 | 'has_commit_access' => 1,// changed |
||
110 | ]; |
||
111 | |||
112 | $this->Developers->saveFromGithub($updatedGithubInfo, $access_token, $developer); |
||
113 | |||
114 | $savedDeveloper = $this->Developers->get($nextId); |
||
115 | $this->assertNotEquals(null, $savedDeveloper); |
||
116 | $this->assertEquals(1231231, $savedDeveloper->github_id); |
||
117 | $this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
||
118 | $this->assertEquals('[email protected]', $savedDeveloper->email); |
||
119 | $this->assertEquals(true, $savedDeveloper->has_commit_access); |
||
120 | } |
||
122 |