Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 40 |
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 |
||
7 | public function testKnockoutConfirmedPasswordField() { |
||
8 | $field = KnockoutConfirmedPasswordField::create("MyField", "My Field"); |
||
9 | $fields = $field->children; |
||
10 | $password_field = $fields->fieldByName('MyField[_Password]'); |
||
11 | $password_confirmed_field = $fields->fieldByName('MyField[_ConfirmPassword]'); |
||
12 | |||
13 | $this->assertNotNull( |
||
14 | $password_field, |
||
15 | "password field is not null" |
||
16 | ); |
||
17 | $this->assertNotNull( |
||
18 | $password_confirmed_field, |
||
19 | "password confirmed field is not null" |
||
20 | ); |
||
21 | $this->assertEquals( |
||
22 | "password", |
||
23 | $password_field->getObservable(), |
||
24 | "observable is set to password by default in the Password field" |
||
25 | ); |
||
26 | $this->assertEquals( |
||
27 | "confirmedPassword", |
||
28 | $password_confirmed_field->getObservable(), |
||
29 | "observable is set to confirmedPassword by default in the Confirmed Password field" |
||
30 | ); |
||
31 | $this->assertEquals( |
||
32 | ['password', 'confirmedPassword'], |
||
33 | $field->getObservables(), |
||
34 | "The function getObservables returns an array of the observables set on the child fields" |
||
35 | ); |
||
36 | |||
37 | |||
38 | |||
39 | $field2 = KnockoutConfirmedPasswordField::create("MyField2", "My Field2") |
||
40 | ->setObservables(['password2', 'confirmedPassword2']); |
||
41 | $fields2 = $field2->children; |
||
42 | |||
43 | $password_field2 = $fields2->fieldByName('MyField2[_Password]'); |
||
44 | $password_confirmed_field2 = $fields2->fieldByName('MyField2[_ConfirmPassword]'); |
||
45 | |||
46 | $this->assertEquals( |
||
47 | "password2", |
||
48 | $password_field2->getObservable(), |
||
49 | "observable is set to password2 through the setObservables method" |
||
50 | ); |
||
51 | $this->assertEquals( |
||
52 | "confirmedPassword2", |
||
53 | $password_confirmed_field2->getObservable(), |
||
54 | "observable is set to confirmedPassword2 through the setObservables method" |
||
55 | ); |
||
56 | $this->assertEquals( |
||
57 | ['password2', 'confirmedPassword2'], |
||
58 | $field2->getObservables(), |
||
59 | "The function getObservables returns an array of the observables set on the child fields" |
||
60 | ); |
||
61 | } |
||
62 | } |
||
64 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.