Conditions | 8 |
Paths | 60 |
Total Lines | 116 |
Code Lines | 74 |
Lines | 7 |
Ratio | 6.03 % |
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 |
||
38 | public function transcode_asset( |
||
39 | $tmpPathInput, |
||
40 | $pathToInputFile, |
||
41 | $pathToOutputFiles, |
||
42 | $metadata = null, |
||
43 | $outputWanted) |
||
44 | { |
||
45 | if ($metadata) { |
||
46 | // Extract an sanitize metadata |
||
47 | $metadata = $this->_extractFileInfo($metadata); |
||
48 | } |
||
49 | |||
50 | $this->cpeLogger->logOut( |
||
51 | "INFO", |
||
52 | basename(__FILE__), |
||
53 | "Start Transcoding Asset '$pathToInputFile' ...", |
||
54 | $this->activityLogKey |
||
55 | ); |
||
56 | |||
57 | View Code Duplication | if ($metadata) |
|
58 | $this->cpeLogger->logOut( |
||
59 | "INFO", |
||
60 | basename(__FILE__), |
||
61 | "Input Video metadata: " . print_r($metadata, true), |
||
62 | $this->activityLogKey |
||
63 | ); |
||
64 | |||
65 | try { |
||
66 | $convertCmd = ""; |
||
67 | |||
68 | // Update output extension file if it ends with '.*' |
||
69 | // Output will take the same extension as input |
||
70 | $this->_updateOutputExtension( |
||
71 | $pathToInputFile, |
||
72 | $outputWanted); |
||
73 | |||
74 | // Custom command |
||
75 | if (isset($outputWanted->{'custom_cmd'}) && |
||
76 | $outputWanted->{'custom_cmd'}) { |
||
77 | $convertCmd = $this->craft_convert_custom_cmd( |
||
78 | $tmpPathInput, |
||
79 | $pathToInputFile, |
||
80 | $pathToOutputFiles, |
||
81 | $metadata, |
||
82 | $outputWanted |
||
83 | ); |
||
84 | } |
||
85 | else { |
||
86 | $convertCmd = $this->craft_convert_cmd( |
||
87 | $tmpPathInput, |
||
88 | $pathToInputFile, |
||
89 | $pathToOutputFiles, |
||
90 | $metadata, |
||
91 | $outputWanted |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | $this->cpeLogger->logOut( |
||
96 | "INFO", |
||
97 | basename(__FILE__), |
||
98 | "CONVERT CMD:\n$convertCmd\n", |
||
99 | $this->activityLogKey |
||
100 | ); |
||
101 | |||
102 | // Use executer to start Converter command |
||
103 | // Use 'capture_progression' function as callback |
||
104 | // Pass video 'duration' as parameter |
||
105 | // Sleep 1sec between turns and callback every 10 turns |
||
106 | // Output progression logs (true) |
||
107 | $this->executer->execute( |
||
108 | $convertCmd, |
||
109 | 1, |
||
110 | array(2 => array("pipe", "w")), |
||
111 | array($this->activityObj, "activityHeartbeat"), |
||
112 | null, |
||
113 | true, |
||
114 | 10 |
||
115 | ); |
||
116 | |||
117 | // Test if we have an output file ! |
||
118 | if (!file_exists($pathToOutputFiles) || |
||
119 | $this->isDirEmpty($pathToOutputFiles)) { |
||
120 | throw new CpeSdk\CpeException( |
||
121 | "Output file '$pathToOutputFiles' hasn't been created successfully or is empty !", |
||
122 | self::TRANSCODE_FAIL |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | // FFProbe the output file and return its information |
||
127 | // XXX: Remove FFprobe for image convertion. Save time |
||
128 | $outputInfo = |
||
129 | $this->getAssetInfo($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
||
130 | } |
||
131 | catch (\Exception $e) { |
||
132 | $this->cpeLogger->logOut( |
||
133 | "ERROR", |
||
134 | basename(__FILE__), |
||
135 | "Execution of command '".$convertCmd."' failed: " . print_r($metadata, true). ". ".$e->getMessage(), |
||
136 | $this->activityLogKey |
||
|
|||
137 | ); |
||
138 | return false; |
||
139 | } |
||
140 | |||
141 | // No error. Transcode successful |
||
142 | $this->cpeLogger->logOut( |
||
143 | "INFO", |
||
144 | basename(__FILE__), |
||
145 | "Transcoding successfull !", |
||
146 | $this->activityLogKey |
||
147 | ); |
||
148 | |||
149 | return [ |
||
150 | "output" => $outputWanted, |
||
151 | "outputInfo" => $outputInfo |
||
152 | ]; |
||
153 | } |
||
154 | |||
237 | } |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.