| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 44 |
| 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 |
||
| 77 | public function testCreate() |
||
| 78 | { |
||
| 79 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
| 80 | $bugReportDecoded = json_decode($bugReport, true); |
||
| 81 | $this->configRequest(array('input' => $bugReport)); |
||
| 82 | $this->post('/incidents/create'); |
||
| 83 | |||
| 84 | $report = $this->Reports->find('all', |
||
| 85 | array('order' => 'Reports.created desc'))->all()->first(); |
||
| 86 | $subject = 'A new report has been submitted ' |
||
| 87 | . 'on the Error Reporting Server: ' |
||
| 88 | . $report['id']; |
||
| 89 | |||
| 90 | // Test notification email |
||
| 91 | $emailContent = Configure::read('test_transport_email'); |
||
| 92 | |||
| 93 | $this->assertEquals('[email protected]', $emailContent['headers']['From']); |
||
| 94 | $this->assertEquals('[email protected]', $emailContent['headers']['To']); |
||
| 95 | $this->assertEquals($subject, $emailContent['headers']['Subject']); |
||
| 96 | |||
| 97 | Configure::write('test_transport_email', NULL); |
||
| 98 | |||
| 99 | $this->post('/incidents/create'); |
||
| 100 | |||
| 101 | $report = $this->Reports->find('all', |
||
| 102 | array('order' => 'Reports.created desc'))->all()->first(); |
||
| 103 | //$report = $report->hydrate(false)->toArray(); |
||
| 104 | $this->Reports->id = $report['id']; |
||
| 105 | $incidents = $this->Reports->getIncidents(); |
||
| 106 | $incidents = $incidents->hydrate(false)->toArray(); |
||
| 107 | $this->assertEquals(2, count($incidents)); |
||
| 108 | $this->assertEquals($bugReportDecoded['exception']['message'], |
||
| 109 | $report['error_message']); |
||
| 110 | $this->assertEquals($bugReportDecoded['exception']['name'], |
||
| 111 | $report['error_name']); |
||
| 112 | $this->assertEquals($bugReportDecoded['pma_version'], |
||
| 113 | $report['pma_version']); |
||
| 114 | $this->configRequest(array('input' => array())); |
||
| 115 | $this->post('/incidents/create'); |
||
| 116 | $result = json_decode($this->_response->body(), true); |
||
| 117 | $this->assertEquals(false, $result['success']); |
||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | // Test invalid Notification email configuration |
||
| 122 | Configure::write('NotificationEmailsTo', ''); |
||
| 123 | |||
| 124 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
| 125 | $bugReportDecoded = json_decode($bugReport, true); |
||
| 126 | $this->configRequest(array('input' => $bugReport)); |
||
| 127 | $this->post('/incidents/create'); |
||
| 128 | |||
| 129 | $report = $this->Reports->find('all', |
||
| 130 | array('order' => 'Reports.created desc'))->all()->first(); |
||
| 131 | $subject = 'A new report has been submitted ' |
||
| 132 | . 'on the Error Reporting Server: ' |
||
| 133 | . $report['id']; |
||
| 134 | |||
| 135 | $emailContent = Configure::read('test_transport_email'); |
||
| 136 | |||
| 137 | // Since no email sent |
||
| 138 | $this->assertEquals(NULL, $emailContent); |
||
| 139 | |||
| 140 | } |
||
| 141 | } |
||
| 142 |
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: