Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
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 testFindOrCreateMemberOverwriteExistingFields() { |
||
58 | $member = new Member(array( |
||
59 | 'Email' => '[email protected]', |
||
60 | 'FirstName' => 'Existing', |
||
61 | 'Surname' => 'Existing', |
||
62 | )); |
||
63 | $member->write(); |
||
64 | |||
65 | $identity = OpauthIdentity::factory(array( |
||
66 | 'auth' => array( |
||
67 | 'provider' => 'Facebook', |
||
68 | 'uid' => 999, |
||
69 | 'info' => array( |
||
70 | 'email' => '[email protected]', |
||
71 | 'first_name' => 'New', |
||
72 | 'last_name' => 'New' |
||
73 | ) |
||
74 | ) |
||
75 | )); |
||
76 | $member = $identity->findOrCreateMember(array('overwriteExistingFields' => false)); |
||
77 | $this->assertEquals( |
||
78 | 'Existing', |
||
79 | $member->FirstName, |
||
80 | 'Does not overwrite unless requested' |
||
81 | ); |
||
82 | |||
83 | $identity = OpauthIdentity::factory(array( |
||
84 | 'auth' => array( |
||
85 | 'provider' => 'Facebook', |
||
86 | 'uid' => 999, |
||
87 | 'info' => array( |
||
88 | 'email' => '[email protected]', |
||
89 | 'first_name' => 'New', |
||
90 | 'last_name' => 'New' |
||
91 | ) |
||
92 | ) |
||
93 | )); |
||
94 | $member = $identity->findOrCreateMember(array('overwriteExistingFields' => array( |
||
95 | 'FirstName' |
||
96 | ))); |
||
97 | $this->assertEquals( |
||
98 | 'New', |
||
99 | $member->FirstName, |
||
100 | 'Overwrites existing fields if requested' |
||
101 | ); |
||
102 | $this->assertEquals( |
||
103 | 'Existing', |
||
104 | $member->Surname, |
||
105 | 'Does not overwrite fields if not present in whitelist' |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | } |
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.