| Conditions | 9 |
| Paths | 6 |
| Total Lines | 68 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 60 | public function run() |
||
|
|
|||
| 61 | { |
||
| 62 | if (is_null($this->model) || empty($this->model->object)) { |
||
| 63 | return ''; |
||
| 64 | } |
||
| 65 | $cacheKey = static::className() . ':' . implode( |
||
| 66 | "_", |
||
| 67 | [ |
||
| 68 | $this->model->object->id, |
||
| 69 | $this->model->id, |
||
| 70 | $this->viewFile, |
||
| 71 | $this->limit, |
||
| 72 | $this->offset, |
||
| 73 | $this->thumbnailOnDemand ? '1' : '0', |
||
| 74 | $this->thumbnailWidth, |
||
| 75 | $this->thumbnailHeight, |
||
| 76 | $this->useWatermark, |
||
| 77 | ] |
||
| 78 | ); |
||
| 79 | $result = Yii::$app->cache->get($cacheKey); |
||
| 80 | if ($result === false) { |
||
| 81 | if ($this->offset > 0 || !is_null($this->limit)) { |
||
| 82 | $images = $this->model->getImages()->limit($this->limit)->offset($this->offset)->all(); |
||
| 83 | } else { |
||
| 84 | $images = $this->model->images; |
||
| 85 | } |
||
| 86 | if ($this->noImageOnEmptyImages === true && count($images) === 0) { |
||
| 87 | return $this->render( |
||
| 88 | 'noimage', |
||
| 89 | [ |
||
| 90 | 'model' => $this->model, |
||
| 91 | 'thumbnailOnDemand' => $this->thumbnailOnDemand, |
||
| 92 | 'thumbnailWidth' => $this->thumbnailWidth, |
||
| 93 | 'thumbnailHeight' => $this->thumbnailHeight, |
||
| 94 | 'useWatermark' => $this->useWatermark, |
||
| 95 | 'additional' => $this->additional, |
||
| 96 | ] |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | $result = $this->render( |
||
| 100 | $this->viewFile, |
||
| 101 | [ |
||
| 102 | 'model' => $this->model, |
||
| 103 | 'images' => $images, |
||
| 104 | 'thumbnailOnDemand' => $this->thumbnailOnDemand, |
||
| 105 | 'thumbnailWidth' => $this->thumbnailWidth, |
||
| 106 | 'thumbnailHeight' => $this->thumbnailHeight, |
||
| 107 | 'useWatermark' => $this->useWatermark, |
||
| 108 | 'additional' => $this->additional, |
||
| 109 | ] |
||
| 110 | ); |
||
| 111 | Yii::$app->cache->set( |
||
| 112 | $cacheKey, |
||
| 113 | $result, |
||
| 114 | 86400, |
||
| 115 | new TagDependency( |
||
| 116 | [ |
||
| 117 | 'tags' => [ |
||
| 118 | ActiveRecordHelper::getCommonTag(Image::className()), |
||
| 119 | ActiveRecordHelper::getCommonTag($this->model->className()), |
||
| 120 | ] |
||
| 121 | ] |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | |||
| 126 | return $result; |
||
| 127 | } |
||
| 128 | } |
||
| 129 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.