Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 40 |
Lines | 0 |
Ratio | 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 testFind() |
||
8 | { |
||
9 | // page needs to be live |
||
10 | $nearPage = $this->objFromFixture('NearestPOIPage', 'StationFinder'); |
||
11 | $this->logInWithPermission('ADMIN'); |
||
12 | $nearPage->doPublish(); |
||
13 | if (Member::currentUser()) { |
||
14 | Member::currentUser()->logOut(); |
||
15 | } |
||
16 | $link = $nearPage->Link(); |
||
17 | error_log('POI PAGE LINK:'.$link); |
||
18 | |||
19 | $url = $link; |
||
20 | error_log('TRYING URL '.$url); |
||
21 | $response = $this->get($url); |
||
22 | $this->assertEquals(200, $response->getStatusCode()); |
||
23 | |||
24 | // location is MBK |
||
25 | $url = $link.'find?lat=13.7444513&lng=100.5290196'; |
||
26 | $response = $this->get($url); |
||
27 | $this->assertEquals(200, $response->getStatusCode()); |
||
28 | $expected = array( |
||
29 | 'Ratchathewi', |
||
30 | 'Phaya Thai', |
||
31 | 'Chit Lom', |
||
32 | 'Victory Monument', |
||
33 | 'Nana', |
||
34 | 'Sanam Pao', |
||
35 | 'Ari', |
||
36 | 'Saphan Khwai', |
||
37 | 'Mo Chit', |
||
38 | ); |
||
39 | $this->assertExactMatchBySelector('table#nearestPOIs td.name', $expected); |
||
40 | |||
41 | // location is victory monument |
||
42 | $url = $link.'find?lat=13.7650776&lng=100.5369724'; |
||
43 | $response = $this->get($url); |
||
44 | $this->assertEquals(200, $response->getStatusCode()); |
||
45 | $expected = array( |
||
46 | 'Victory Monument', |
||
47 | 'Phaya Thai', |
||
48 | 'Sanam Pao', |
||
49 | 'Ratchathewi', |
||
50 | 'Ari', |
||
51 | 'Chit Lom', |
||
52 | 'Nana', |
||
53 | 'Saphan Khwai', |
||
54 | 'Mo Chit', |
||
55 | ); |
||
56 | $this->assertExactMatchBySelector('table#nearestPOIs td.name', $expected); |
||
57 | } |
||
58 | } |
||
59 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.