| Conditions | 8 |
| Paths | 134 |
| Total Lines | 67 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 100 | public function generate() : void |
||
| 101 | { |
||
| 102 | $ffmpeg = $this->getFFMpeg(); |
||
| 103 | $videoFormat = $this->getVideoFormat(); |
||
| 104 | |||
| 105 | try { |
||
| 106 | $cutPoints = $this->getCutPoints(); |
||
| 107 | |||
| 108 | /** @var Video $video */ |
||
| 109 | $video = $ffmpeg->open($this->sourceFile); |
||
| 110 | |||
| 111 | $files = []; |
||
| 112 | foreach ($cutPoints as $k => $cutPoint) { |
||
| 113 | $partFile = $this->options->getTempFolder() . '/' . md5($this->sourceFile) . '_' . ($k + 1) . '.avi'; |
||
| 114 | |||
| 115 | //remove audio track |
||
| 116 | $video->addFilter(new SimpleFilter(['-an'])); |
||
| 117 | |||
| 118 | $video->filters()->clip( |
||
| 119 | TimeCode::fromSeconds($cutPoint), |
||
| 120 | TimeCode::fromSeconds($this->options->getOutputDuration() / count($cutPoints)) |
||
| 121 | ); |
||
| 122 | |||
| 123 | $video->filters()->resize( |
||
| 124 | new Dimension( |
||
| 125 | (int) round($this->options->getDimensionWidth()), |
||
| 126 | (int) round($this->options->getDimensionWidth() / $this->getRatio()) |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | $video->filters()->framerate(new FrameRate($this->options->getFrameRate()), 1); |
||
| 130 | $video->save($videoFormat, $partFile); |
||
| 131 | |||
| 132 | $files[] = $partFile; |
||
| 133 | $this->addTempFileToRemove($partFile); |
||
| 134 | } |
||
| 135 | |||
| 136 | if (count($files) == 1) { |
||
| 137 | rename($files[0], $this->destination); |
||
| 138 | } else { |
||
| 139 | /** @var Video $video */ |
||
| 140 | $video = $ffmpeg->open($files[0]); |
||
| 141 | |||
| 142 | if (is_file($this->destination)) { |
||
| 143 | unlink($this->destination); |
||
| 144 | } |
||
| 145 | |||
| 146 | $video |
||
| 147 | ->concat($files) |
||
| 148 | ->saveFromSameCodecs($this->destination); |
||
| 149 | } |
||
| 150 | |||
| 151 | if ($this->options->getCropRatio() and ($this->options->getCropRatio() != $this->getRatio())) { |
||
| 152 | $fileCropped = $this->options->getTempFolder() . '/' . md5($this->sourceFile) . '_cropped.avi'; |
||
| 153 | |||
| 154 | $video = $ffmpeg->open($this->destination); |
||
| 155 | $video->addFilter(new CropCenterFilter($this->options->getCropRatio())); |
||
| 156 | $video->save($videoFormat, $fileCropped); |
||
| 157 | rename($fileCropped, $this->destination); |
||
| 158 | } |
||
| 159 | } catch (RuntimeException $e) { |
||
| 160 | $message = $e->getMessage(); |
||
| 161 | |||
| 162 | if ($e->getPrevious() instanceof ExecutionFailureException) { |
||
| 163 | $message = $e->getPrevious()->getMessage(); |
||
| 164 | } |
||
| 165 | |||
| 166 | throw new GiffhangerException(sprintf('%s', $message)); |
||
| 167 | } |
||
| 170 |