| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 113 | public function behaviors() |
||
| 114 | { |
||
| 115 | return [ |
||
| 116 | [ |
||
| 117 | 'class' => TimestampBehavior::className(), |
||
| 118 | 'createdAtAttribute' => 'date_create', |
||
| 119 | 'updatedAtAttribute' => 'date_update', |
||
| 120 | 'value' => new \yii\db\Expression('NOW()'), |
||
| 121 | ], |
||
| 122 | |||
| 123 | [ |
||
| 124 | 'class' => 'creocoder\taggable\TaggableBehavior', |
||
| 125 | // 'tagValuesAsArray' => false, |
||
| 126 | // 'tagRelation' => 'tags', |
||
| 127 | 'tagValueAttribute' => 'title', |
||
| 128 | 'tagFrequencyAttribute' => 'count', |
||
| 129 | ], |
||
| 130 | |||
| 131 | [ |
||
| 132 | 'class' => 'rkit\filemanager\behaviors\FileBehavior', |
||
| 133 | 'attributes' => [ |
||
| 134 | 'text' => [ |
||
| 135 | 'storage' => 'rkit\filemanager\storages\LocalStorage', |
||
| 136 | 'rules' => [ |
||
| 137 | 'mimeTypes' => ['image/png', 'image/jpg', 'image/jpeg'], |
||
| 138 | 'extensions' => ['jpg', 'jpeg', 'png'], |
||
| 139 | 'maxSize' => 1024 * 1024 * 1, // 1 MB |
||
| 140 | 'tooBig' => Yii::t('app.messages', 'File size must not exceed') . ' 1Mb' |
||
| 141 | ] |
||
| 142 | ], |
||
| 143 | 'preview' => [ |
||
| 144 | 'storage' => 'rkit\filemanager\storages\LocalStorage', |
||
| 145 | 'saveFilePath' => true, |
||
| 146 | 'rules' => [ |
||
| 147 | 'imageSize' => ['minWidth' => 300, 'minHeight' => 300], |
||
| 148 | 'mimeTypes' => ['image/png', 'image/jpg', 'image/jpeg'], |
||
| 149 | 'extensions' => ['jpg', 'jpeg', 'png'], |
||
| 150 | 'maxSize' => 1024 * 1024 * 1, // 1 MB |
||
| 151 | 'tooBig' => Yii::t('app.messages', 'File size must not exceed') . ' 1Mb' |
||
| 152 | ], |
||
| 153 | 'preset' => [ |
||
| 154 | '200x200' => function ($realPath, $publicPath, $thumbPath) { |
||
| 155 | Image::make($realPath . $publicPath) |
||
| 156 | ->fit(200, 200) |
||
| 157 | ->save($realPath . $thumbPath, 100); |
||
| 158 | }, |
||
| 159 | '1000x1000' => function ($realPath, $publicPath, $thumbPath) { |
||
| 160 | Image::make($realPath . $publicPath) |
||
| 161 | ->resize(1000, 1000, function ($constraint) { |
||
| 162 | $constraint->aspectRatio(); |
||
| 163 | $constraint->upsize(); |
||
| 164 | }) |
||
| 165 | ->save(null, 100); |
||
| 166 | }, |
||
| 167 | ], |
||
| 168 | 'applyPresetAfterUpload' => '*' |
||
| 169 | ], |
||
| 170 | 'gallery' => [ |
||
| 171 | 'storage' => 'rkit\filemanager\storages\LocalStorage', |
||
| 172 | 'multiple' => true, |
||
| 173 | 'rules' => [ |
||
| 174 | 'imageSize' => ['minWidth' => 300, 'minHeight' => 300], |
||
| 175 | 'mimeTypes' => ['image/png', 'image/jpg', 'image/jpeg'], |
||
| 176 | 'extensions' => ['jpg', 'jpeg', 'png'], |
||
| 177 | 'maxSize' => 1024 * 1024 * 1, // 1 MB |
||
| 178 | 'tooBig' => Yii::t('app.messages', 'File size must not exceed') . ' 1Mb' |
||
| 179 | ], |
||
| 180 | 'preset' => [ |
||
| 181 | '80x80' => function ($realPath, $publicPath, $thumbPath) { |
||
| 182 | Image::make($realPath . $publicPath) |
||
| 183 | ->fit(80, 80) |
||
| 184 | ->save($realPath . $thumbPath, 100); |
||
| 185 | }, |
||
| 186 | ], |
||
| 187 | ] |
||
| 188 | ] |
||
| 189 | ] |
||
| 190 | ]; |
||
| 191 | } |
||
| 192 | |||
| 290 |