Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
64 | public function testMain() |
||
65 | { |
||
66 | // Mock functions `curl_exec` and `curl_getinfo` in GithubApiComponent |
||
67 | // so that we don't actually hit the Github Api |
||
68 | $curlExecMock = $this->getFunctionMock('\App\Controller\Component', 'curl_exec'); |
||
69 | $curlGetInfoMock = $this->getFunctionMock('\App\Controller\Component', 'curl_getinfo'); |
||
70 | |||
71 | $issueResponse = file_get_contents(TESTS . 'Fixture' . DS . 'issue_response.json'); |
||
72 | $decodedResponse = json_decode($issueResponse, true); |
||
73 | $decodedResponse['state'] = 'closed'; |
||
74 | $issueResponseWithClosed = json_encode($decodedResponse); |
||
75 | |||
76 | $curlExecMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
77 | $issueResponse, $issueResponse, $issueResponseWithClosed |
||
78 | ); |
||
79 | $curlGetInfoMock->expects($this->exactly(3))->willReturnOnConsecutiveCalls( |
||
80 | 200, 200, 200 |
||
81 | ); |
||
82 | |||
83 | // Fetch all linked reports |
||
84 | $reports = $this->Reports->find( |
||
85 | 'all', |
||
86 | array( |
||
87 | 'conditions' => array( |
||
88 | 'sourceforge_bug_id IS NOT NULL', |
||
89 | 'NOT' => array( |
||
90 | 'status' => 'resolved' |
||
91 | ) |
||
92 | ) |
||
93 | ) |
||
94 | ); |
||
95 | $this->assertEquals(3, $reports->count()); |
||
96 | |||
97 | $this->SyncGithubIssueStates->main(); |
||
98 | |||
99 | // Fetch all linked reports |
||
100 | $reports = $this->Reports->find( |
||
101 | 'all', |
||
102 | array( |
||
103 | 'conditions' => array( |
||
104 | 'sourceforge_bug_id IS NOT NULL', |
||
105 | 'NOT' => array( |
||
106 | 'status' => 'resolved' |
||
107 | ) |
||
108 | ) |
||
109 | ) |
||
110 | ); |
||
111 | $this->assertEquals(2, $reports->count()); |
||
112 | |||
113 | // Fetch all closed reports |
||
114 | $reports = $this->Reports->find( |
||
115 | 'all', |
||
116 | array( |
||
117 | 'conditions' => array( |
||
118 | 'sourceforge_bug_id IS NOT NULL', |
||
119 | 'status' => 'resolved' |
||
120 | ) |
||
121 | ) |
||
122 | ); |
||
123 | $this->assertEquals(1, $reports->count()); |
||
124 | $report5 = $this->Reports->get(4); |
||
125 | $this->assertEquals('resolved', $report5->status); |
||
126 | } |
||
127 | } |
||
128 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: