| Conditions | 11 |
| Paths | 21 |
| Total Lines | 60 |
| 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 |
||
| 27 | protected function inlineImage($excerpt) |
||
| 28 | { |
||
| 29 | $save = true; |
||
| 30 | $external = false; |
||
| 31 | |||
| 32 | $image = parent::inlineImage($excerpt); |
||
| 33 | |||
| 34 | if (!isset($image)) { |
||
| 35 | return null; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (preg_match('~^(?:f|ht)tps?://~i', $image['element']['attributes']['src'])) { |
||
| 39 | $external = true; |
||
| 40 | } |
||
| 41 | |||
| 42 | preg_match('/'.self::PATTERN.'/s', $image['element']['attributes']['src'], $matches); |
||
| 43 | if (empty($matches)) { |
||
| 44 | return $image; |
||
| 45 | } |
||
| 46 | $image['element']['attributes']['src'] = $matches[1]; |
||
| 47 | |||
| 48 | if ($this->config === null) { |
||
| 49 | return $image; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (array_key_exists(3, $matches) && $matches[3] == 'resize') { |
||
| 53 | $resize = $matches[4]; |
||
| 54 | |||
| 55 | $image['element']['attributes']['width'] = $resize; |
||
| 56 | |||
| 57 | if (extension_loaded('gd')) { |
||
| 58 | if ($external) { |
||
| 59 | $img = Image::make($image['element']['attributes']['src']); |
||
| 60 | } else { |
||
| 61 | $img = Image::make($this->config->getStaticPath().'/'.$image['element']['attributes']['src']); |
||
| 62 | } |
||
| 63 | $img->resize($resize, null, function ($constraint) { |
||
| 64 | $constraint->aspectRatio(); |
||
| 65 | $constraint->upsize(); |
||
| 66 | }); |
||
| 67 | if ($save) { |
||
| 68 | if ($external) { |
||
| 69 | $imgPath = (string) $img->encode('data-url'); |
||
| 70 | } else { |
||
| 71 | $imgPath = '/'.self::TMP_DIR.'/images/thumbs/'.$resize.$image['element']['attributes']['src']; |
||
| 72 | $dir = Util::getFS()->makePathRelative( |
||
| 73 | dirname($imgPath), |
||
| 74 | '/'.self::TMP_DIR.'/images/thumbs/'.$resize |
||
| 75 | ); |
||
| 76 | Util::getFS()->mkdir($this->config->getDestinationDir().'/'.self::TMP_DIR.'/images/thumbs/'.$resize.'/'.$dir); |
||
| 77 | $img->save($this->config->getDestinationDir().$imgPath); |
||
| 78 | $imgPath = '/images/thumbs/'.$resize.$image['element']['attributes']['src']; |
||
| 79 | } |
||
| 80 | $image['element']['attributes']['src'] = $imgPath; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return $image; |
||
| 86 | } |
||
| 87 | } |
||
| 88 |