| Conditions | 7 |
| Paths | 7 |
| Total Lines | 57 |
| Code Lines | 30 |
| 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 |
||
| 121 | private function imageResizeMake($image, $imagetype, $imagePath, $baseSize, $imageSizeInfo) |
||
| 122 | { |
||
| 123 | // サイズ変更後の画像データを生成 |
||
| 124 | $outImage = ImageCreateTrueColor($imageSizeInfo['reSizeX'], $imageSizeInfo['reSizeY']); |
||
| 125 | if (!$outImage) { |
||
| 126 | // リサイズ後の画像作成失敗 |
||
| 127 | return false; |
||
| 128 | } |
||
| 129 | |||
| 130 | //透過GIF.PNG対策 |
||
| 131 | $this->setTPinfo($image, $imageSizeInfo['sizeX'], $imageSizeInfo['sizeY']); |
||
| 132 | |||
| 133 | // 画像で使用する色を透過度を指定して作成 |
||
| 134 | $bgcolor = imagecolorallocatealpha($outImage, @$this->tp["red"], @$this->tp["green"], @$this->tp["blue"], @$this->tp["alpha"]); |
||
| 135 | |||
| 136 | // 塗り潰す |
||
| 137 | imagefill($outImage, 0, 0, $bgcolor); |
||
| 138 | // 透明色を定義 |
||
| 139 | imagecolortransparent($outImage, $bgcolor); |
||
| 140 | //!透過GIF.PNG対策 |
||
| 141 | // 画像リサイズ |
||
| 142 | $ret = imagecopyresampled($outImage, $image, 0, 0, 0, 0, $imageSizeInfo['reSizeX'], $imageSizeInfo['reSizeY'], $imageSizeInfo['sizeX'], $imageSizeInfo['sizeY']); |
||
| 143 | |||
| 144 | if ($ret === false) { |
||
| 145 | // リサイズ失敗 |
||
| 146 | return false; |
||
| 147 | } |
||
| 148 | |||
| 149 | ImageDestroy($image); |
||
| 150 | |||
| 151 | // 画像保存 |
||
| 152 | $imagepathinfo = $this->getPathInfo($imagePath, $baseSize); |
||
| 153 | //resizeファイルを格納するディレクトリを作成 |
||
| 154 | if ( |
||
| 155 | !$this->mkdir($imagepathinfo['resize_dir'], 0777, true) |
||
|
|
|||
| 156 | ) { |
||
| 157 | return false; |
||
| 158 | } |
||
| 159 | |||
| 160 | switch ($imagetype) { |
||
| 161 | case IMAGETYPE_GIF: |
||
| 162 | ImageGIF($outImage, $imagepathinfo['resize_filepath']); |
||
| 163 | break; |
||
| 164 | case IMAGETYPE_JPEG: |
||
| 165 | ImageJPEG($outImage, $imagepathinfo['resize_filepath'], 100); |
||
| 166 | break; |
||
| 167 | case IMAGETYPE_PNG: |
||
| 168 | ImagePNG($outImage, $imagepathinfo['resize_filepath']); |
||
| 169 | break; |
||
| 170 | default: |
||
| 171 | return false; |
||
| 172 | } |
||
| 173 | |||
| 174 | ImageDestroy($outImage); |
||
| 175 | |||
| 176 | return true; |
||
| 177 | } |
||
| 178 | |||
| 245 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.