| Conditions | 3 |
| Paths | 3 |
| Total Lines | 70 |
| Code Lines | 46 |
| Lines | 12 |
| Ratio | 17.14 % |
| Changes | 1 | ||
| 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 |
||
| 31 | public function viewAction(){
|
||
| 32 | |||
| 33 | $this->initialize(); |
||
| 34 | $calendar = new \Anax\Calendar\CCalendar(); |
||
| 35 | $calendar->getValues(); |
||
| 36 | $calendar->generateCalenderData(); |
||
| 37 | $month = $calendar->getMonthNumber(); |
||
| 38 | $year = $calendar->getYear(); |
||
| 39 | |||
| 40 | $date = $this->dispatcher->getParam('date');
|
||
| 41 | $_GET = array(); |
||
| 42 | $currentDate = $year ."-". $month ."-". sprintf('%02s',$date);
|
||
| 43 | |||
| 44 | |||
| 45 | $events = $this->events->findEventsOfDay($currentDate); |
||
| 46 | $eventCount = $this->events->getEventCountPerDayOfMonth($month); |
||
| 47 | |||
| 48 | $form = new \Mos\HTMLForm\CForm(); |
||
| 49 | |||
| 50 | $form = $form->create([], [ |
||
| 51 | 'title' => [ |
||
| 52 | 'type' => 'text', |
||
| 53 | 'label' => 'Title', |
||
| 54 | 'required' => true, |
||
| 55 | 'validation' => ['not_empty'], |
||
| 56 | ], |
||
| 57 | 'time' => [ |
||
| 58 | 'type' => 'date', |
||
| 59 | 'label' => 'Date for event', |
||
| 60 | 'required' => true, |
||
| 61 | 'validation' => ['not_empty'], |
||
| 62 | ], |
||
| 63 | 'content' => [ |
||
| 64 | 'type' => 'textarea', |
||
| 65 | 'label' => 'Content', |
||
| 66 | 'required' => true, |
||
| 67 | 'validation' => ['not_empty'], |
||
| 68 | ], |
||
| 69 | 'submit' => [ |
||
| 70 | 'type' => 'submit', |
||
| 71 | 'callback' => function($form) {
|
||
| 72 | $form->saveInSession = true; |
||
| 73 | return true; |
||
| 74 | } |
||
| 75 | ], |
||
| 76 | ]); |
||
| 77 | |||
| 78 | // Check the status of the form |
||
| 79 | $status = $form->check(); |
||
| 80 | |||
| 81 | View Code Duplication | if ($status === true) {
|
|
| 82 | |||
| 83 | $this->dispatcher->forward([ |
||
| 84 | 'controller' => 'event', |
||
| 85 | 'action' => 'add', |
||
| 86 | ]); |
||
| 87 | |||
| 88 | } else if ($status === false) {
|
||
| 89 | |||
| 90 | var_dump('Check method returned false');
|
||
| 91 | die; |
||
| 92 | } |
||
| 93 | |||
| 94 | $this->views->add('calendar/calendar', [
|
||
| 95 | 'content' => $calendar->printResponsiveCalendar($eventCount), |
||
| 96 | 'form' => $form->getHTML(), |
||
| 97 | 'events' => $events, |
||
| 98 | ]); |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 230 | } |
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: