| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 57 | public function testCreate() |
||
| 58 | { |
||
| 59 | $action = 'foo'; |
||
| 60 | $method = RequestMethods::POST; |
||
| 61 | $showUrl = 'bar'; |
||
| 62 | $entityId = '96368723-292f-4943-9903-83ad552fc118'; |
||
| 63 | $password = 'baz'; |
||
| 64 | $username = 'zorro79'; |
||
| 65 | $email = '[email protected]'; |
||
| 66 | $canLogin = true; |
||
| 67 | $isGravatarAllowed = true; |
||
| 68 | $allUserGroups = [ |
||
| 69 | new UserGroup('dc2abea5-8021-4228-882a-31b91fe3687a', 'ug-22', 'UG 22'), |
||
| 70 | new UserGroup('75ccb863-ce02-4b2d-b655-af4c92f2dbe6', 'ug-73', 'UG 73'), |
||
| 71 | new UserGroup('aff15988-2170-4b10-9aad-4ed2ea19f73e', 'ug-112', 'UG 112'), |
||
| 72 | new UserGroup('143522ce-5e0e-4abb-8c4b-67d88ba90d9d', 'ug-432', 'UG 432'), |
||
| 73 | ]; |
||
| 74 | $userGroups = [ |
||
| 75 | $allUserGroups[0], |
||
| 76 | $allUserGroups[2], |
||
| 77 | ]; |
||
| 78 | $allUserLanguages = [ |
||
| 79 | new UserLanguage('5027689a-39da-4810-b0b6-2ae42e387698', 'ul-52', 'UL 52'), |
||
| 80 | new UserLanguage('afb423cc-6272-4ff4-8a62-e28cac6cb1d1', 'ul-77', 'UL 77'), |
||
| 81 | new UserLanguage('38030970-10be-4b6b-9dc6-38d6a74310ca', 'ul-93', 'UL 93'), |
||
| 82 | new UserLanguage('15c3f8ef-d5ff-4210-a5a2-3732f4073a1b', 'ul-94', 'UL 94'), |
||
| 83 | ]; |
||
| 84 | $userLanguage = $allUserLanguages[1]; |
||
| 85 | |||
| 86 | $this->userGroupRepoMock->expects($this->any())->method('getAll')->willReturn($allUserGroups); |
||
| 87 | $this->userLanguageRepoMock->expects($this->any())->method('getAll')->willReturn($allUserLanguages); |
||
| 88 | |||
| 89 | $entityStub = new Entity( |
||
| 90 | $entityId, |
||
| 91 | $username, |
||
| 92 | $email, |
||
| 93 | $password, |
||
| 94 | $canLogin, |
||
| 95 | $isGravatarAllowed, |
||
| 96 | $userLanguage, |
||
| 97 | $userGroups |
||
| 98 | ); |
||
| 99 | |||
| 100 | $form = (string)$this->sut->create($action, $method, $showUrl, $entityStub); |
||
| 101 | |||
| 102 | $this->assertStringContainsString($action, $form); |
||
| 103 | $this->assertStringContainsString($showUrl, $form); |
||
| 104 | $this->assertStringContainsString('CSRF', $form); |
||
| 105 | $this->assertStringContainsString('POST', $form); |
||
| 106 | $this->assertStringContainsString('username', $form); |
||
| 107 | $this->assertStringContainsString('email', $form); |
||
| 108 | $this->assertStringContainsString('password', $form); |
||
| 109 | $this->assertStringContainsString('password_confirmed', $form); |
||
| 110 | $this->assertStringContainsString('raw_password', $form); |
||
| 111 | $this->assertStringContainsString('raw_password_confirmed', $form); |
||
| 112 | $this->assertStringContainsString('can_login', $form); |
||
| 113 | $this->assertStringContainsString('is_gravatar_allowed', $form); |
||
| 114 | $this->assertStringContainsString('user_group_ids', $form); |
||
| 115 | $this->assertStringContainsString('user_language_id', $form); |
||
| 116 | $this->assertStringContainsString('selected', $form); |
||
| 117 | $this->assertStringContainsString('button', $form); |
||
| 118 | } |
||
| 139 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: