Conditions | 9 |
Paths | 9 |
Total Lines | 103 |
Code Lines | 54 |
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 |
||
21 | public function do_activity($task) |
||
22 | { |
||
23 | // Save output object |
||
24 | $this->output = $this->input->{'output_asset'}; |
||
25 | |||
26 | // Custom validation for transcoding. Set $this->output |
||
27 | $this->validate_input(); |
||
28 | |||
29 | $this->cpeLogger->log_out( |
||
30 | "INFO", |
||
31 | basename(__FILE__), |
||
32 | "Preparing Asset transcoding ...", |
||
33 | $this->activityLogKey |
||
34 | ); |
||
35 | |||
36 | // Call parent do_activity: |
||
37 | // It download the input file we will process. |
||
38 | parent::do_activity($task); |
||
39 | |||
40 | // Set output path to store result files |
||
41 | $this->set_output_path($task); |
||
42 | |||
43 | // Result output |
||
44 | $result = null; |
||
45 | |||
46 | // Load the right transcoder base on input_type |
||
47 | // Get asset detailed info |
||
48 | switch ($this->input->{'input_asset'}->{'type'}) |
||
49 | { |
||
50 | case self::VIDEO: |
||
51 | require_once __DIR__.'/transcoders/VideoTranscoder.php'; |
||
52 | |||
53 | // Instanciate transcoder to output Videos |
||
54 | $videoTranscoder = new VideoTranscoder($this, $task); |
||
55 | |||
56 | // Check preset file, read its content and add its data to output object |
||
57 | if ($this->output->{'type'} == self::VIDEO && |
||
58 | isset($this->output->{'preset'})) |
||
59 | { |
||
60 | // Validate output preset |
||
61 | $videoTranscoder->validate_preset($this->output); |
||
62 | |||
63 | // Set preset value |
||
64 | $this->output->{'preset_values'} = |
||
65 | $videoTranscoder->get_preset_values($this->output); |
||
66 | } |
||
67 | |||
68 | # If we have metadata, we expect the output of ffprobe |
||
69 | $metadata = null; |
||
70 | if (isset($this->input->{'input_asset_metadata'})) |
||
71 | $metadata = $this->input->{'input_asset_metadata'}; |
||
72 | |||
73 | // Perform transcoding |
||
74 | $result = $videoTranscoder->transcode_asset( |
||
75 | $this->tmpPathInput, |
||
76 | $this->pathToInputFile, |
||
77 | $this->pathToOutputFiles, |
||
78 | $metadata, |
||
79 | $this->output |
||
80 | ); |
||
81 | |||
82 | unset($videoTranscoder); |
||
83 | |||
84 | break; |
||
85 | case self::IMAGE: |
||
86 | require_once __DIR__.'/transcoders/ImageTranscoder.php'; |
||
87 | |||
88 | // Instanciate transcoder to output Images |
||
89 | $imageTranscoder = new ImageTranscoder($this, $task); |
||
90 | |||
91 | # If we have metadata, we expect the output of ffprobe |
||
92 | $metadata = null; |
||
93 | if (isset($this->input->{'input_asset_metadata'})) |
||
94 | $metadata = $this->input->{'input_asset_metadata'}; |
||
95 | |||
96 | // Perform transcoding |
||
97 | $result = $imageTranscoder->transcode_asset( |
||
98 | $this->tmpPathInput, |
||
99 | $this->pathToInputFile, |
||
100 | $this->pathToOutputFiles, |
||
101 | $metadata, |
||
102 | $this->output |
||
103 | ); |
||
104 | |||
105 | unset($imageTranscoder); |
||
106 | |||
107 | break; |
||
108 | case self::AUDIO: |
||
109 | |||
110 | break; |
||
111 | case self::DOC: |
||
112 | |||
113 | break; |
||
114 | default: |
||
115 | throw new CpeSdk\CpeException("Unknown input asset 'type'! Abording ...", |
||
116 | self::UNKOWN_INPUT_TYPE); |
||
117 | } |
||
118 | |||
119 | // Upload resulting file |
||
120 | $this->upload_result_files($task); |
||
121 | |||
122 | return $result; |
||
123 | } |
||
124 | |||
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.