| Conditions | 5 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 17 |
| 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 |
||
| 49 | protected function doActualConvert() |
||
| 50 | { |
||
| 51 | /* |
||
| 52 | $im = \Jcupitt\Vips\Image::newFromFile(__DIR__ . '/images/small.jpg'); |
||
| 53 | //$im->writeToFile(__DIR__ . '/images/small-vips.webp', ["Q" => 10]); |
||
| 54 | $im->webpsave(__DIR__ . '/images/small-vips.webp', [ |
||
| 55 | "Q" => 80, |
||
| 56 | 'near_lossless' => true |
||
| 57 | ]); |
||
| 58 | return; |
||
| 59 | */ |
||
| 60 | |||
| 61 | $result = vips_image_new_from_file($this->source); |
||
|
|
|||
| 62 | if ($result === -1) { |
||
| 63 | /*throw new ConversionFailedException( |
||
| 64 | 'Failed creating new vips image from file: ' . $this->source |
||
| 65 | );*/ |
||
| 66 | $message = vips_error_buffer(); |
||
| 67 | throw new ConversionFailedException($message); |
||
| 68 | |||
| 69 | } |
||
| 70 | |||
| 71 | if (!is_array($result)) { |
||
| 72 | throw new ConversionFailedException( |
||
| 73 | 'vips_image_new_from_file did not return an array, which we expected' |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | |||
| 77 | if (count($result) != 1) { |
||
| 78 | throw new ConversionFailedException( |
||
| 79 | 'vips_image_new_from_file did not return an array of length 1 as we expected - length was: ' . count($result) |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | $im = array_shift($result); |
||
| 84 | |||
| 85 | // webpsave options are described here: |
||
| 86 | // https://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-webpsave |
||
| 87 | $result = vips_call('webpsave', $im, $this->destination, [ |
||
| 88 | "Q" => $this->getCalculatedQuality(), |
||
| 89 | //'lossless' => true, |
||
| 90 | //'lossless' => $this->options['lossless'], // boolean |
||
| 91 | //'preset' |
||
| 92 | //'smart_subsample' // boolean |
||
| 93 | |||
| 94 | // hm, when I use near_lossless, I get error: "no property named `near_lossless'" |
||
| 95 | // btw: beware that if this is used, q must be 20, 40, 60 or 80 (according to link above) |
||
| 96 | //'near_lossless' => true, // boolean |
||
| 97 | |||
| 98 | //'alpha_q' // int |
||
| 99 | 'strip' => $this->options['metadata'] == 'none' |
||
| 100 | ]); |
||
| 101 | if ($result === -1) { |
||
| 102 | $message = vips_error_buffer(); |
||
| 103 | throw new ConversionFailedException($message); |
||
| 104 | } |
||
| 107 |