Conditions | 4 |
Paths | 4 |
Total Lines | 51 |
Code Lines | 31 |
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 |
||
94 | public function process(array $projects, $options = array()) |
||
95 | { |
||
96 | if (empty($projects)) { |
||
97 | return array(); |
||
98 | } |
||
99 | |||
100 | $reports = array(); |
||
101 | $release_history = new ReleaseHistory(); |
||
102 | |||
103 | /** @var Project $project */ |
||
104 | foreach ($projects as $project) { |
||
105 | $release_history->prepare($project); |
||
106 | |||
107 | $event = new CerbereDoActionEvent($this, $project); |
||
108 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DO_ACTION, $event); |
||
109 | |||
110 | if ($filename = $project->getFilename()) { |
||
|
|||
111 | $current_dir = getcwd(); |
||
112 | // Change current directory to the module directory. |
||
113 | chdir($project->getWorkingDirectory()); |
||
114 | |||
115 | $hacked = new HackedProject($project); |
||
116 | $result = $hacked->computeReport(); |
||
117 | |||
118 | $report = array( |
||
119 | 'project' => $project->getProject(), |
||
120 | 'type' => $project->getProjectType(), |
||
121 | 'version' => $project->getVersion(), |
||
122 | 'version_date' => $project->getDatestamp(), |
||
123 | 'status' => $result['status'], |
||
124 | 'status_label' => HackedProject::getStatusLabel($result['status']), |
||
125 | 'modified' => $result['counts']['different'], |
||
126 | 'deleted' => $result['counts']['missing'], |
||
127 | ); |
||
128 | |||
129 | $event = new CerbereReportActionEvent($this, $project, $report); |
||
130 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_REPORT_ACTION, $event); |
||
131 | $report = $event->getReport(); |
||
132 | |||
133 | $reports[] = $report; |
||
134 | |||
135 | // Restore current directory. |
||
136 | chdir($current_dir); |
||
137 | } |
||
138 | |||
139 | $event = new CerbereDoneActionEvent($this, $project); |
||
140 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DONE_ACTION, $event); |
||
141 | } |
||
142 | |||
143 | return $reports; |
||
144 | } |
||
145 | } |
||
146 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.