| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 38 |
| 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 |
||
| 69 | public function testDataTables() |
||
| 70 | { |
||
| 71 | $this->get('/reports/data_tables?sEcho=1&iDisplayLength=25'); |
||
| 72 | $expected = array( |
||
| 73 | 'iTotalRecords' => 3, |
||
| 74 | 'iTotalDisplayRecords' => 3, |
||
| 75 | 'sEcho' => 1, |
||
| 76 | 'aaData' => array( |
||
| 77 | array("<input type='checkbox' name='reports[]' value='1'/>", 1, 'error2', 'Lorem ipsum dolor sit amet', '4.0', 'New', 'js', '1'), |
||
| 78 | array("<input type='checkbox' name='reports[]' value='2'/>", 2, 'error2', 'Lorem ipsum dolor sit amet', '4.0', 'New', 'js', '1'), |
||
| 79 | array("<input type='checkbox' name='reports[]' value='4'/>", 4, 'error1', 'Lorem ipsum dolor sit amet', '3.8', 'New', 'js', '2'), |
||
| 80 | ), |
||
| 81 | ); |
||
| 82 | $this->assertEquals($expected, json_decode($this->_response->body(), true)); |
||
| 83 | |||
| 84 | $this->get('/reports/data_tables?sEcho=1&sSearch=error2&bSearchable_2=true&iSortCol_0=0&sSortDir_0=desc&bSortable_0=true&iSortingCols=2&iDisplayLength=25'); |
||
| 85 | $expected = array( |
||
| 86 | 'iTotalRecords' => 3, |
||
| 87 | 'iTotalDisplayRecords' => 2, |
||
| 88 | 'sEcho' => 1, |
||
| 89 | 'aaData' => array( |
||
| 90 | array("<input type='checkbox' name='reports[]' value='1'/>", 1, 'error2', 'Lorem ipsum dolor sit amet', '4.0', 'New', 'js', '1'), |
||
| 91 | array("<input type='checkbox' name='reports[]' value='2'/>", 2, 'error2', 'Lorem ipsum dolor sit amet', '4.0', 'New', 'js', '1'), |
||
| 92 | ), |
||
| 93 | ); |
||
| 94 | $result = json_decode($this->_response->body(), true); |
||
| 95 | $this->assertEquals($expected, $result); |
||
| 96 | |||
| 97 | $this->get('/reports/data_tables?sEcho=1&sSearch_1=1&iDisplayLength=25'); |
||
| 98 | $expected = array( |
||
| 99 | 'iTotalRecords' => 3, |
||
| 100 | 'iTotalDisplayRecords' => 1, |
||
| 101 | 'sEcho' => 1, |
||
| 102 | 'aaData' => array( |
||
| 103 | array("<input type='checkbox' name='reports[]' value='1'/>", 1, 'error2', 'Lorem ipsum dolor sit amet', '4.0', 'New', 'js', '1'), |
||
| 104 | ), |
||
| 105 | ); |
||
| 106 | $result = json_decode($this->_response->body(), true); |
||
| 107 | $this->assertEquals($expected, $result); |
||
| 108 | |||
| 109 | $this->get('/reports/data_tables?sEcho=1&sSearch_1=error&iDisplayLength=25'); |
||
| 110 | $expected = array( |
||
| 111 | 'iTotalRecords' => 3, |
||
| 112 | 'iTotalDisplayRecords' => 0, |
||
| 113 | 'sEcho' => 1, |
||
| 114 | 'aaData' => array( |
||
| 115 | ), |
||
| 116 | ); |
||
| 117 | $result = json_decode($this->_response->body(), true); |
||
| 118 | $this->assertEquals($expected, $result); |
||
| 119 | } |
||
| 120 | |||
| 158 |
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: