| Conditions | 1 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 58 |
| 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 |
||
| 103 | private function checkImportedData() |
||
| 104 | { |
||
| 105 | // Checkout categories |
||
| 106 | $categoryService = self::$dic->get(CategoryService::class); |
||
| 107 | |||
| 108 | $this->assertEquals('Linux', $categoryService->getByName('Linux')->getName()); |
||
| 109 | $this->assertEquals('Windows', $categoryService->getByName('Windows')->getName()); |
||
| 110 | $this->assertEquals('Servers', $categoryService->getByName('Servers')->getName()); |
||
| 111 | $this->assertEquals('General', $categoryService->getByName('General')->getName()); |
||
| 112 | |||
| 113 | $this->assertEquals(11, $this->conn->getRowCount('Category')); |
||
| 114 | |||
| 115 | // Checkout clients |
||
| 116 | $client = self::$dic->get(ClientService::class)->getByName('KeePass'); |
||
| 117 | |||
| 118 | $this->assertEquals('KeePass', $client->getName()); |
||
| 119 | |||
| 120 | $this->assertEquals(4, $this->conn->getRowCount('Client')); |
||
| 121 | |||
| 122 | // Checkout accounts |
||
| 123 | $accountService = self::$dic->get(AccountService::class); |
||
| 124 | |||
| 125 | // 1st account |
||
| 126 | $filter = new AccountSearchFilter(); |
||
| 127 | $filter->setClientId($client->getId()); |
||
| 128 | |||
| 129 | $data = $accountService->getByFilter($filter); |
||
| 130 | |||
| 131 | $this->assertCount(5, $data); |
||
| 132 | |||
| 133 | $this->assertEquals(3, $data[0]->getId()); |
||
| 134 | $this->assertEquals(1, $data[0]->getUserId()); |
||
| 135 | $this->assertEquals(2, $data[0]->getUserGroupId()); |
||
| 136 | $this->assertEquals('DC1', $data[0]->getName()); |
||
| 137 | $this->assertEquals('KeePass', $data[0]->getClientName()); |
||
| 138 | $this->assertEquals('Windows', $data[0]->getCategoryName()); |
||
| 139 | $this->assertEquals('192.168.100.1', $data[0]->getUrl()); |
||
| 140 | $this->assertEquals('ADS server', $data[0]->getNotes()); |
||
| 141 | $this->assertEquals('administrator', $data[0]->getLogin()); |
||
| 142 | |||
| 143 | $pass = $accountService->getPasswordForId($data[0]->getId()); |
||
| 144 | |||
| 145 | $this->assertEquals('k6V4iIAeR9SBOprLMUGV', Crypt::decrypt($pass->getPass(), $pass->getKey(), '12345678900')); |
||
| 146 | |||
| 147 | // 2nd account |
||
| 148 | |||
| 149 | $this->assertEquals(4, $data[1]->getId()); |
||
| 150 | $this->assertEquals(1, $data[1]->getUserId()); |
||
| 151 | $this->assertEquals(2, $data[1]->getUserGroupId()); |
||
| 152 | $this->assertEquals('debian', $data[1]->getName()); |
||
| 153 | $this->assertEquals('KeePass', $data[1]->getClientName()); |
||
| 154 | $this->assertEquals('Linux', $data[1]->getCategoryName()); |
||
| 155 | $this->assertEquals('http://debian.org', $data[1]->getUrl()); |
||
| 156 | $this->assertEquals("Some notes about the server", $data[1]->getNotes()); |
||
| 157 | $this->assertEquals('root', $data[1]->getLogin()); |
||
| 158 | |||
| 159 | $pass = $accountService->getPasswordForId($data[1]->getId()); |
||
| 160 | |||
| 161 | $this->assertEquals('TKr321zqCZhgbzmmAX13', Crypt::decrypt($pass->getPass(), $pass->getKey(), '12345678900')); |
||
| 162 | |||
| 163 | // 3rd account |
||
| 164 | $this->assertEquals(5, $data[2]->getId()); |
||
| 165 | $this->assertEquals(1, $data[2]->getUserId()); |
||
| 166 | $this->assertEquals(2, $data[2]->getUserGroupId()); |
||
| 167 | $this->assertEquals('proxy', $data[2]->getName()); |
||
| 168 | $this->assertEquals('KeePass', $data[2]->getClientName()); |
||
| 169 | $this->assertEquals('Linux', $data[2]->getCategoryName()); |
||
| 170 | $this->assertEquals('192.168.0.1', $data[2]->getUrl()); |
||
| 171 | $this->assertEquals('Some notes about proxy server', $data[2]->getNotes()); |
||
| 172 | $this->assertEquals('admin', $data[2]->getLogin()); |
||
| 173 | |||
| 174 | $pass = $accountService->getPasswordForId($data[2]->getId()); |
||
| 175 | |||
| 176 | $this->assertEquals('TKr321zqCZhgbzmmAX13', Crypt::decrypt($pass->getPass(), $pass->getKey(), '12345678900')); |
||
| 177 | |||
| 178 | $this->assertEquals(6, $data[3]->getId()); |
||
| 179 | $this->assertEquals(1, $data[3]->getUserId()); |
||
| 180 | $this->assertEquals(2, $data[3]->getUserGroupId()); |
||
| 181 | $this->assertEquals('Sample Entry', $data[3]->getName()); |
||
| 182 | $this->assertEquals('NewDatabase', $data[3]->getCategoryName()); |
||
| 183 | |||
| 184 | $this->assertEquals(7, $data[4]->getId()); |
||
| 185 | $this->assertEquals(1, $data[4]->getUserId()); |
||
| 186 | $this->assertEquals(2, $data[4]->getUserGroupId()); |
||
| 187 | $this->assertEquals('Sample Entry #2', $data[4]->getName()); |
||
| 188 | $this->assertEquals('NewDatabase', $data[4]->getCategoryName()); |
||
| 189 | |||
| 190 | $this->assertEquals(7, $this->conn->getRowCount('Account')); |
||
| 191 | } |
||
| 193 |