| Conditions | 4 |
| Paths | 4 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 89 | public function process(array $projects, $options = array()) |
||
| 90 | { |
||
| 91 | if (empty($projects)) { |
||
| 92 | return array(); |
||
| 93 | } |
||
| 94 | |||
| 95 | $reports = array(); |
||
| 96 | $release_history = new ReleaseHistory(); |
||
| 97 | |||
| 98 | /** @var Project $project */ |
||
| 99 | foreach ($projects as $project) { |
||
| 100 | $release_history->prepare($project); |
||
| 101 | |||
| 102 | $event = new CerbereDoActionEvent($this, $project); |
||
| 103 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DO_ACTION, $event); |
||
| 104 | |||
| 105 | if ($filename = $project->getFilename()) { |
||
| 106 | $current_dir = getcwd(); |
||
| 107 | // Change current directory to the module directory. |
||
| 108 | chdir(dirname($filename)); |
||
| 109 | |||
| 110 | $hacked = new HackedProject($project); |
||
| 111 | $result = $hacked->computeReport(); |
||
| 112 | |||
| 113 | $report = array( |
||
| 114 | 'project' => $project->getProject(), |
||
| 115 | 'type' => $project->getProjectType(), |
||
| 116 | 'version' => $project->getVersion(), |
||
| 117 | 'version_date' => $project->getDatestamp(), |
||
| 118 | 'status' => $result['status'], |
||
| 119 | 'status_label' => HackedProject::getStatusLabel($result['status']), |
||
| 120 | 'modified' => $result['counts']['different'], |
||
| 121 | 'deleted' => $result['counts']['missing'], |
||
| 122 | ); |
||
| 123 | |||
| 124 | $event = new CerbereReportActionEvent($this, $project, $report); |
||
| 125 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_REPORT_ACTION, $event); |
||
| 126 | $report = $event->getReport(); |
||
| 127 | |||
| 128 | $reports[] = $report; |
||
| 129 | |||
| 130 | // Restore current directory. |
||
| 131 | chdir($current_dir); |
||
| 132 | } |
||
| 133 | |||
| 134 | $event = new CerbereDoneActionEvent($this, $project); |
||
| 135 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DONE_ACTION, $event); |
||
| 136 | } |
||
| 137 | |||
| 138 | return $reports; |
||
| 139 | } |
||
| 140 | } |
||
| 141 |
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: