| Conditions | 9 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 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 |
||
| 126 | private function upload_result_files($task) |
||
| 127 | { |
||
| 128 | // Sanitize output bucket and file path "/" |
||
| 129 | $s3Bucket = str_replace("//", "/", |
||
| 130 | $this->output->{"bucket"}); |
||
| 131 | |||
| 132 | // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
||
| 133 | // XXX: Add tmp workflowID to output bucket to seperate upload |
||
| 134 | // XXX: For testing only ! |
||
| 135 | // $s3Bucket .= "/".$task["workflowExecution"]["workflowId"]; |
||
|
|
|||
| 136 | // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
||
| 137 | |||
| 138 | // Set S3 options |
||
| 139 | $options = array("rrs" => false, "encrypt" => false); |
||
| 140 | if (isset($this->output->{'s3_rrs'}) && |
||
| 141 | $this->output->{'s3_rrs'} == true) { |
||
| 142 | $options['rrs'] = true; |
||
| 143 | } |
||
| 144 | if (isset($this->output->{'s3_encrypt'}) && |
||
| 145 | $this->output->{'s3_encrypt'} == true) { |
||
| 146 | $options['encrypt'] = true; |
||
| 147 | } |
||
| 148 | |||
| 149 | // Open '$pathToOutputFiles' to read it and send all files to S3 bucket |
||
| 150 | if (!$handle = opendir($this->pathToOutputFiles)) { |
||
| 151 | throw new CpeSdk\CpeException("Can't open tmp path '$this->pathToOutputFiles'!", |
||
| 152 | self::TMP_PATH_OPEN_FAIL); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Upload all resulting files sitting in $pathToOutputFiles to S3 |
||
| 156 | while ($entry = readdir($handle)) { |
||
| 157 | if ($entry == "." || $entry == "..") { |
||
| 158 | continue; |
||
| 159 | } |
||
| 160 | |||
| 161 | // Destination path on S3. Sanitizing |
||
| 162 | $s3Location = $this->output->{'output_file_info'}['dirname']."/$entry"; |
||
| 163 | $s3Location = str_replace("//", "/", $s3Location); |
||
| 164 | |||
| 165 | // Send to S3. We reference the callback s3_put_processing_callback |
||
| 166 | // The callback ping back SWF so we stay alive |
||
| 167 | $s3Output = $this->s3Utils->put_file_into_s3( |
||
| 168 | $s3Bucket, |
||
| 169 | $s3Location, |
||
| 170 | "$this->pathToOutputFiles/$entry", |
||
| 171 | $options, |
||
| 172 | array($this, "s3_put_processing_callback"), |
||
| 173 | $task |
||
| 174 | ); |
||
| 175 | // We delete the TMP file once uploaded |
||
| 176 | unlink("$this->pathToOutputFiles/$entry"); |
||
| 177 | |||
| 178 | $this->cpeLogger->log_out("INFO", basename(__FILE__), |
||
| 179 | $s3Output['msg'], |
||
| 180 | $this->activityLogKey); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 244 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.