| Conditions | 5 |
| Paths | 7 |
| Total Lines | 67 |
| Code Lines | 22 |
| 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 |
||
| 76 | protected function doActualConvert() |
||
| 77 | { |
||
| 78 | |||
| 79 | $options = $this->options; |
||
| 80 | |||
| 81 | try { |
||
| 82 | $im = new \Gmagick($this->source); |
||
| 83 | } catch (\Exception $e) { |
||
| 84 | throw new ConversionFailedException( |
||
| 85 | 'Failed creating Gmagick object of file', |
||
| 86 | 'Failed creating Gmagick object of file: "' . $this->source . '" - Gmagick threw an exception.', |
||
| 87 | $e |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | |||
| 91 | /* |
||
| 92 | Seems there are currently no way to set webp options |
||
| 93 | As noted in the following link, it should probably be done with a $im->addDefinition() method |
||
| 94 | - but that isn't exposed (yet) |
||
| 95 | (TODO: see if anyone has answered...) |
||
| 96 | https://stackoverflow.com/questions/47294962/how-to-write-lossless-webp-files-with-perlmagick |
||
| 97 | */ |
||
| 98 | // The following two does not have any effect... How to set WebP options? |
||
| 99 | //$im->setimageoption('webp', 'webp:lossless', $options['lossless'] ? 'true' : 'false'); |
||
| 100 | //$im->setimageoption('WEBP', 'method', strval($options['method'])); |
||
| 101 | |||
| 102 | // It seems there is no COMPRESSION_WEBP... |
||
| 103 | // http://php.net/manual/en/imagick.setimagecompression.php |
||
| 104 | //$im->setImageCompression(Imagick::COMPRESSION_JPEG); |
||
| 105 | //$im->setImageCompression(Imagick::COMPRESSION_UNDEFINED); |
||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | $im->setimageformat('WEBP'); |
||
| 110 | |||
| 111 | if ($options['metadata'] == 'none') { |
||
| 112 | // Strip metadata and profiles |
||
| 113 | $im->stripImage(); |
||
| 114 | } |
||
| 115 | |||
| 116 | // Ps: Imagick automatically uses same quality as source, when no quality is set |
||
| 117 | // This feature is however not present in Gmagick |
||
| 118 | $im->setcompressionquality($this->getCalculatedQuality()); |
||
| 119 | |||
| 120 | try { |
||
| 121 | // We call getImageBlob(). |
||
| 122 | // That method is undocumented, but it is there! |
||
| 123 | // - just like it is in imagick, as pointed out here: |
||
| 124 | // https://www.php.net/manual/ru/gmagick.readimageblob.php |
||
| 125 | |||
| 126 | /** @scrutinizer ignore-call */ |
||
| 127 | $imageBlob = $im->getImageBlob(); |
||
| 128 | } catch (\ImagickException $e) { |
||
| 129 | throw new ConversionFailedException( |
||
| 130 | 'Gmagick failed converting - getImageBlob() threw an exception)', |
||
| 131 | 0, |
||
| 132 | $e |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | |||
| 137 | //$success = $im->writeimagefile(fopen($destination, 'wb')); |
||
| 138 | $success = @file_put_contents($this->destination, $imageBlob); |
||
| 139 | |||
| 140 | if (!$success) { |
||
| 141 | throw new ConversionFailedException('Failed writing file'); |
||
| 142 | } else { |
||
| 143 | //$logger->logLn('sooms we made it!'); |
||
| 147 |