| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 43 | public function setUp() { |
||
| 44 | parent::setUp(); |
||
| 45 | |||
| 46 | $this->testUser = $this->getUniqueID('user_'); |
||
| 47 | // needed because some parts of code call "getRequest()" and "getSession()" |
||
| 48 | $session = $this->getMockBuilder('\OC\Session\Memory') |
||
| 49 | ->disableOriginalConstructor() |
||
| 50 | ->getMock(); |
||
| 51 | $session->expects($this->any()) |
||
| 52 | ->method('get') |
||
| 53 | ->with('user_id') |
||
| 54 | ->will($this->returnValue($this->testUser)); |
||
| 55 | $userObject = $this->getMock('\OCP\IUser'); |
||
| 56 | $userObject->expects($this->any()) |
||
| 57 | ->method('getUId') |
||
| 58 | ->will($this->returnValue($this->testUser)); |
||
| 59 | $userSession = $this->getMockBuilder('\OC\User\Session') |
||
| 60 | ->disableOriginalConstructor() |
||
| 61 | ->getMock(); |
||
| 62 | $userSession->expects($this->any()) |
||
| 63 | ->method('getUser') |
||
| 64 | ->will($this->returnValue($userObject)); |
||
| 65 | $userSession->expects($this->any()) |
||
| 66 | ->method('getSession') |
||
| 67 | ->will($this->returnValue($session)); |
||
| 68 | \OC::$server->registerService('UserSession', function (\OCP\IServerContainer $c) use ($userSession){ |
||
|
|
|||
| 69 | return $userSession; |
||
| 70 | }); |
||
| 71 | |||
| 72 | |||
| 73 | $this->backend = new Backend\Database($this->testUser); |
||
| 74 | $this->abinfo = array('displayname' => uniqid('display_')); |
||
| 75 | $this->ab = new AddressBook($this->backend, $this->abinfo); |
||
| 76 | $this->provider = new AddressbookProvider($this->ab); |
||
| 77 | |||
| 78 | $card = new \OCA\Contacts\VObject\VCard(); |
||
| 79 | $uid = substr(md5($this->getUniqueID()), 0, 10); |
||
| 80 | $card->add('UID', $uid); |
||
| 81 | $card->add('FN', 'Max Mustermann'); |
||
| 82 | $id = $this->ab->addChild($card); |
||
| 83 | Utils\Properties::updateIndex($id, $card); |
||
| 84 | $this->contactIds[] = $id; |
||
| 85 | |||
| 86 | // Add extra contact |
||
| 87 | $card = new \OCA\Contacts\VObject\VCard(); |
||
| 88 | $uid = substr(md5(rand().time()), 0, 10); |
||
| 89 | $card->add('UID', $uid); |
||
| 90 | $card->add('FN', 'Jan Janssens'); |
||
| 91 | $id = $this->ab->addChild($card); |
||
| 92 | Utils\Properties::updateIndex($id, $card); |
||
| 93 | $this->contactIds[] = $id; |
||
| 94 | } |
||
| 95 | |||
| 126 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.