| Conditions | 3 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 41 |
| 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 |
||
| 75 | public function testSaveFromGithub() |
||
| 76 | { |
||
| 77 | $i = 0; |
||
| 78 | while (1) { |
||
| 79 | try { |
||
| 80 | $i++; |
||
| 81 | $savedDeveloper = $this->Developers->get($i); |
||
|
|
|||
| 82 | } catch (\Cake\Datasource\Exception\RecordNotFoundException $e) { |
||
| 83 | break; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $nextId = $i; |
||
| 88 | |||
| 89 | $githubInfo = array( |
||
| 90 | 'login' => 'pma-bot', |
||
| 91 | 'id' => 1231231, |
||
| 92 | 'gravatar_id' => '', |
||
| 93 | 'url' => 'https://api.github.com/users/pma-bot', |
||
| 94 | 'name' => 'PMA BOT', |
||
| 95 | 'email' => '[email protected]', |
||
| 96 | 'has_commit_access' => 0 |
||
| 97 | ); |
||
| 98 | $developer = $this->Developers->newEntity(); |
||
| 99 | $access_token = 'abc'; |
||
| 100 | |||
| 101 | $this->Developers->saveFromGithub($githubInfo, $access_token, $developer); |
||
| 102 | |||
| 103 | $savedDeveloper = $this->Developers->get($nextId); |
||
| 104 | $this->assertNotEquals(null, $savedDeveloper); |
||
| 105 | $this->assertEquals(1231231, $savedDeveloper->github_id); |
||
| 106 | $this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
||
| 107 | $this->assertEquals('[email protected]', $savedDeveloper->email); |
||
| 108 | $this->assertEquals(false, $savedDeveloper->has_commit_access); |
||
| 109 | |||
| 110 | $updatedGithubInfo = array( |
||
| 111 | 'login' => 'pma-bot', |
||
| 112 | 'id' => 1231231, |
||
| 113 | 'gravatar_id' => '', |
||
| 114 | 'url' => 'https://api.github.com/users/pma-bot', |
||
| 115 | 'name' => 'PMA BOT', |
||
| 116 | 'email' => '[email protected]', |
||
| 117 | 'has_commit_access' => 1 // changed |
||
| 118 | ); |
||
| 119 | |||
| 120 | $this->Developers->saveFromGithub($updatedGithubInfo, $access_token, $developer); |
||
| 121 | |||
| 122 | $savedDeveloper = $this->Developers->get($nextId); |
||
| 123 | $this->assertNotEquals(null, $savedDeveloper); |
||
| 124 | $this->assertEquals(1231231, $savedDeveloper->github_id); |
||
| 125 | $this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
||
| 126 | $this->assertEquals('[email protected]', $savedDeveloper->email); |
||
| 127 | $this->assertEquals(true, $savedDeveloper->has_commit_access); |
||
| 128 | |||
| 129 | } |
||
| 130 | } |
||
| 131 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.