| Conditions | 20 | 
| Paths | 384 | 
| Total Lines | 105 | 
| 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  | 
            ||
| 68 | public function buildArray()  | 
            ||
| 69 |     { | 
            ||
| 70 | $results = array();  | 
            ||
| 71 | |||
| 72 | $query = DealerShedulesQuery::create();  | 
            ||
| 73 | |||
| 74 | // this is the sql feature for regular schedule  | 
            ||
| 75 | $query->filterByPeriodNull();  | 
            ||
| 76 | $query->filterByClosed(false);  | 
            ||
| 77 | |||
| 78 |         if ($id = $this->getId()) { | 
            ||
| 79 | $query->filterById($id);  | 
            ||
| 80 | }  | 
            ||
| 81 | |||
| 82 |         if ($day = $this->getDay()) { | 
            ||
| 83 | $query->filterByDay($day);  | 
            ||
| 84 | }  | 
            ||
| 85 | |||
| 86 |         if ($dealer_id = $this->getDealerId()) { | 
            ||
| 87 | $query->filterByDealerId($dealer_id);  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 90 |         foreach ($this->getOrder() as $order) { | 
            ||
| 91 |             switch ($order) { | 
            ||
| 92 | case 'id':  | 
            ||
| 93 | $query->orderById();  | 
            ||
| 94 | break;  | 
            ||
| 95 | case 'id-reverse':  | 
            ||
| 96 | $query->orderById(Criteria::DESC);  | 
            ||
| 97 | break;  | 
            ||
| 98 | case 'day':  | 
            ||
| 99 | $query->orderByDay();  | 
            ||
| 100 | break;  | 
            ||
| 101 | case 'day-reverse':  | 
            ||
| 102 | $query->orderByDay(Criteria::DESC);  | 
            ||
| 103 | break;  | 
            ||
| 104 | case 'begin':  | 
            ||
| 105 | $query->orderByBegin();  | 
            ||
| 106 | break;  | 
            ||
| 107 | case 'begin-reverse':  | 
            ||
| 108 | $query->orderByBegin(Criteria::DESC);  | 
            ||
| 109 | break;  | 
            ||
| 110 | default:  | 
            ||
| 111 | break;  | 
            ||
| 112 | }  | 
            ||
| 113 | }  | 
            ||
| 114 | |||
| 115 |         if ($this->getMergeDay()) { | 
            ||
| 116 | $query->orderByBegin();  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 | $dealerSchedules = $query->find();  | 
            ||
| 120 | |||
| 121 |         if ($this->getMergeDay()) { | 
            ||
| 122 | $dealerCount = count($dealerSchedules);  | 
            ||
| 123 | |||
| 124 |             for ($i = 0; $i < $dealerCount; $i++) { | 
            ||
| 125 | |||
| 126 |                 if (isset($dealerSchedules[$i])) { | 
            ||
| 127 | |||
| 128 | // if the next result has the same dates, same day, then concat the morning and afternoon hours  | 
            ||
| 129 | if (  | 
            ||
| 130 | ($dealerSchedules[$i+1] !== null)  | 
            ||
| 131 | && ($dealerSchedules[$i]->getDay() == $dealerSchedules[$i+1]->getDay())  | 
            ||
| 132 | && ($dealerSchedules[$i]->getDealerId() == $dealerSchedules[$i+1]->getDealerId())  | 
            ||
| 133 |                     ) { | 
            ||
| 134 | $end = $dealerSchedules[$i+1]->getEnd();  | 
            ||
| 135 |                         if ($dealerSchedules[$i]->getEnd()->format('H\hi') === $dealerSchedules[$i+1]->getBegin()->format('H\hi')) { | 
            ||
| 136 | $formattedHours = date_format($dealerSchedules[$i]->getBegin(), 'H\hi') . $this->getHourSeparator() . date_format($dealerSchedules[$i+1]->getEnd(), 'H\hi');  | 
            ||
| 137 |                         } else { | 
            ||
| 138 | $formattedHours = date_format($dealerSchedules[$i]->getBegin(), 'H\hi') . $this->getHourSeparator() . date_format($dealerSchedules[$i]->getEnd(), 'H\hi') . $this->getHalfDaySeparator() . date_format($dealerSchedules[$i+1]->getBegin(), 'H\hi') . $this->getHourSeparator() . date_format($dealerSchedules[$i+1]->getEnd(), 'H\hi');  | 
            ||
| 139 | }  | 
            ||
| 140 | unset($dealerSchedules[$i+1]);  | 
            ||
| 141 |                     } else { | 
            ||
| 142 | $end = $dealerSchedules[$i]->getEnd();  | 
            ||
| 143 | $formattedHours = date_format($dealerSchedules[$i]->getBegin(), 'H\hi') . $this->getHourSeparator() . date_format($dealerSchedules[$i]->getEnd(), 'H\hi');  | 
            ||
| 144 | }  | 
            ||
| 145 | |||
| 146 | $results[] = array(  | 
            ||
| 147 | 'ID' => $dealerSchedules[$i]->getId(),  | 
            ||
| 148 | 'DEALER_ID' => $dealerSchedules[$i]->getDealerId(),  | 
            ||
| 149 | 'DAY' => $dealerSchedules[$i]->getDay(),  | 
            ||
| 150 | 'DAY_LABEL' => $this->getDayLabel($dealerSchedules[$i]->getDay()),  | 
            ||
| 151 | 'BEGIN' => $dealerSchedules[$i]->getBegin(),  | 
            ||
| 152 | 'END' => $end,  | 
            ||
| 153 | 'FORMATTED_HOURS' => $formattedHours,  | 
            ||
| 154 | );  | 
            ||
| 155 | }  | 
            ||
| 156 | }  | 
            ||
| 157 |         } else { | 
            ||
| 158 |             foreach ($dealerSchedules as $dealerSchedule) { | 
            ||
| 159 | $results[] = array(  | 
            ||
| 160 | 'DEALER_ID' => $dealerSchedule->getDealerId(),  | 
            ||
| 161 | 'ID' => $dealerSchedule->getId(),  | 
            ||
| 162 | 'DAY' => $dealerSchedule->getDay(),  | 
            ||
| 163 | 'DAY_LABEL' => $this->getDayLabel($dealerSchedule->getDay()),  | 
            ||
| 164 | 'BEGIN' => $dealerSchedule->getBegin(),  | 
            ||
| 165 | 'END' => $dealerSchedule->getEnd(),  | 
            ||
| 166 | 'FORMATTED_HOURS' => date_format($dealerSchedule->getBegin(), 'H\hi') . $this->getHourSeparator() . date_format($dealerSchedule->getEnd(), 'H\hi')  | 
            ||
| 167 | );  | 
            ||
| 168 | }  | 
            ||
| 169 | }  | 
            ||
| 170 | |||
| 171 | return $results;  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 186 | }  |