| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 43 |
| 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 | $this->post('/incidents/create'); |
||
| 98 | |||
| 99 | $report = $this->Reports->find('all', |
||
| 100 | array('order' => 'Reports.created desc'))->all()->first(); |
||
| 101 | //$report = $report->hydrate(false)->toArray(); |
||
| 102 | $this->Reports->id = $report['id']; |
||
| 103 | $incidents = $this->Reports->getIncidents(); |
||
| 104 | $incidents = $incidents->hydrate(false)->toArray(); |
||
| 105 | $this->assertEquals(2, count($incidents)); |
||
| 106 | $this->assertEquals($bugReportDecoded['exception']['message'], |
||
| 107 | $report['error_message']); |
||
| 108 | $this->assertEquals($bugReportDecoded['exception']['name'], |
||
| 109 | $report['error_name']); |
||
| 110 | $this->assertEquals($bugReportDecoded['pma_version'], |
||
| 111 | $report['pma_version']); |
||
| 112 | $this->configRequest(array('input' => array())); |
||
| 113 | $this->post('/incidents/create'); |
||
| 114 | $result = json_decode($this->_response->body(), true); |
||
| 115 | $this->assertEquals(false, $result['success']); |
||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | // Test invalid Notification email configuration |
||
| 120 | Configure::write('NotificationEmailsTo', ''); |
||
| 121 | |||
| 122 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
| 123 | $bugReportDecoded = json_decode($bugReport, true); |
||
| 124 | $this->configRequest(array('input' => $bugReport)); |
||
| 125 | $this->post('/incidents/create'); |
||
| 126 | |||
| 127 | $report = $this->Reports->find('all', |
||
| 128 | array('order' => 'Reports.created desc'))->all()->first(); |
||
| 129 | $subject = 'A new report has been submitted ' |
||
| 130 | . 'on the Error Reporting Server: ' |
||
| 131 | . $report['id']; |
||
| 132 | |||
| 133 | $emailContent = Configure::read('test_transport_email'); |
||
| 134 | |||
| 135 | // Since no email sent |
||
| 136 | $this->assertEquals(null, $emailContent); |
||
| 137 | |||
| 138 | } |
||
| 139 | } |
||
| 140 |
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: