| Conditions | 6 |
| Paths | 5 |
| Total Lines | 65 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 56 | protected function addRightsWorksheet() |
||
| 57 | { |
||
| 58 | $ee = bab_functionality::get('ExcelExport'); |
||
| 59 | /* @var $ee Func_ExcelExport */ |
||
| 60 | |||
| 61 | $worksheet = $this->workbook->addWorksheet(absences_translate('Vacation rights')); |
||
| 62 | |||
| 63 | $col = 0; |
||
| 64 | $worksheet->setColumn($col, $col++, 30); // description |
||
| 65 | $worksheet->setColumn($col, $col++, 25); // type |
||
| 66 | $worksheet->setColumn($col, $col++, 15); // quantity |
||
| 67 | $worksheet->setColumn($col, $col++, 15); // consumed |
||
| 68 | $worksheet->setColumn($col, $col++, 15); // waiting |
||
| 69 | $worksheet->setColumn($col, $col++, 15); // balance |
||
| 70 | $worksheet->setColumn($col, $col++, 15); // begin |
||
| 71 | $worksheet->setColumn($col, $col++, 15); // end |
||
| 72 | $worksheet->setColumn($col, $col++, 10); // Accessible |
||
| 73 | |||
| 74 | $header = $this->header; |
||
|
|
|||
| 75 | |||
| 76 | |||
| 77 | $row =0; |
||
| 78 | $col =0; |
||
| 79 | $worksheet->write($row, $col++, $this->agent->getName()); |
||
| 80 | $row++; |
||
| 81 | |||
| 82 | $col =0; |
||
| 83 | $worksheet->write($row, $col++, absences_translate('Description') , $header); |
||
| 84 | $worksheet->write($row, $col++, absences_translate('Type') , $header); |
||
| 85 | $worksheet->write($row, $col++, absences_translate('Initial quantity') , $header); |
||
| 86 | $worksheet->write($row, $col++, absences_translate('Consumed') , $header); |
||
| 87 | $worksheet->write($row, $col++, absences_translate('Waiting approval') , $header); |
||
| 88 | $worksheet->write($row, $col++, absences_translate('Balance') , $header); |
||
| 89 | $worksheet->write($row, $col++, absences_translate('Begin date') , $header); |
||
| 90 | $worksheet->write($row, $col++, absences_translate('End date') , $header); |
||
| 91 | $worksheet->write($row, $col++, absences_translate('Accessible') , $header); |
||
| 92 | |||
| 93 | $row++; |
||
| 94 | foreach($this->agent->getAgentRightManagerIterator() as $agentRight) { |
||
| 95 | $col =0; |
||
| 96 | |||
| 97 | /*@var $agentRight absences_AgentRight */ |
||
| 98 | |||
| 99 | $right = $agentRight->getRight(); |
||
| 100 | |||
| 101 | $accessible = $agentRight->isAccessibleByValidityPeriod() |
||
| 102 | && $agentRight->isAccessibleOnPeriod(time(), time()) |
||
| 103 | && $agentRight->isAcessibleByDirectoryEntry() |
||
| 104 | && $right->isAccessibleIfFixed(); |
||
| 105 | |||
| 106 | $worksheet->writeString($row, $col++, $right->description); |
||
| 107 | $worksheet->writeString($row, $col++, $right->getType()->name); |
||
| 108 | $worksheet->writeNumber($row, $col++, $agentRight->getQuantity(), $this->quantity); |
||
| 109 | $worksheet->writeNumber($row, $col++, $agentRight->getConfirmedQuantity(), $this->quantity); |
||
| 110 | $worksheet->writeNumber($row, $col++, $agentRight->getWaitingQuantity(), $this->quantity); |
||
| 111 | $worksheet->writeNumber($row, $col++, $agentRight->getBalance(), $this->quantity); |
||
| 112 | $worksheet->write($row, $col++, $ee->getExcelDate(bab_mktime($right->date_begin)), $this->date); |
||
| 113 | $worksheet->write($row, $col++, $ee->getExcelDate(bab_mktime($right->date_end)), $this->date); |
||
| 114 | $worksheet->write($row, $col++, $accessible ? '1':'0'); |
||
| 115 | |||
| 116 | $row++; |
||
| 117 | } |
||
| 118 | |||
| 119 | |||
| 120 | } |
||
| 121 | |||
| 179 |
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: