| Conditions | 9 |
| Paths | 36 |
| Total Lines | 108 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | public function Raise($aMsg, $aHalt = true) |
||
| 24 | { |
||
| 25 | $img_iconerror = |
||
| 26 | 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV' . |
||
| 27 | 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/' . |
||
| 28 | 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY' . |
||
| 29 | 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea' . |
||
| 30 | 'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx' . |
||
| 31 | 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4' . |
||
| 32 | '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+' . |
||
| 33 | 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6' . |
||
| 34 | 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3' . |
||
| 35 | 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0' . |
||
| 36 | '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS' . |
||
| 37 | 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk' . |
||
| 38 | 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc' . |
||
| 39 | 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx' . |
||
| 40 | 'qL72fwAAAABJRU5ErkJggg=='; |
||
| 41 | |||
| 42 | if (function_exists('imagetypes')) { |
||
| 43 | $supported = imagetypes(); |
||
| 44 | } else { |
||
| 45 | $supported = 0; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (!function_exists('imagecreatefromstring')) { |
||
| 49 | $supported = 0; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (ob_get_length() || headers_sent() || !($supported & IMG_PNG)) { |
||
| 53 | // Special case for headers already sent or that the installation doesn't support |
||
| 54 | // the PNG format (which the error icon is encoded in). |
||
| 55 | // Dont return an image since it can't be displayed |
||
| 56 | die($this->iTitle . ' ' . $aMsg); |
||
|
|
|||
| 57 | } |
||
| 58 | |||
| 59 | $aMsg = wordwrap($aMsg, 55); |
||
| 60 | $lines = substr_count($aMsg, "\n"); |
||
| 61 | |||
| 62 | // Create the error icon GD |
||
| 63 | $erricon = Image\Image::CreateFromString(base64_decode($img_iconerror, true)); |
||
| 64 | |||
| 65 | // Create an image that contains the error text. |
||
| 66 | $w = 400; |
||
| 67 | $h = 100 + 15 * max(0, $lines - 3); |
||
| 68 | |||
| 69 | $img = new Image\Image($w, $h); |
||
| 70 | |||
| 71 | // Drop shadow |
||
| 72 | $img->SetColor('gray'); |
||
| 73 | $img->FilledRectangle(5, 5, $w - 1, $h - 1, 10); |
||
| 74 | $img->SetColor('gray:0.7'); |
||
| 75 | $img->FilledRectangle(5, 5, $w - 3, $h - 3, 10); |
||
| 76 | |||
| 77 | // Window background |
||
| 78 | $img->SetColor('lightblue'); |
||
| 79 | $img->FilledRectangle(1, 1, $w - 5, $h - 5); |
||
| 80 | $img->CopyCanvasH($img->img, $erricon, 5, 30, 0, 0, 40, 40); |
||
| 81 | |||
| 82 | // Window border |
||
| 83 | $img->SetColor('black'); |
||
| 84 | $img->Rectangle(1, 1, $w - 5, $h - 5); |
||
| 85 | $img->Rectangle(0, 0, $w - 4, $h - 4); |
||
| 86 | |||
| 87 | // Window top row |
||
| 88 | $img->SetColor('darkred'); |
||
| 89 | for ($y = 3; $y < 18; $y += 2) { |
||
| 90 | $img->Line(1, $y, $w - 6, $y); |
||
| 91 | } |
||
| 92 | |||
| 93 | // "White shadow" |
||
| 94 | $img->SetColor('white'); |
||
| 95 | |||
| 96 | // Left window edge |
||
| 97 | $img->Line(2, 2, 2, $h - 5); |
||
| 98 | $img->Line(2, 2, $w - 6, 2); |
||
| 99 | |||
| 100 | // "Gray button shadow" |
||
| 101 | $img->SetColor('darkgray'); |
||
| 102 | |||
| 103 | // Gray window shadow |
||
| 104 | $img->Line(2, $h - 6, $w - 5, $h - 6); |
||
| 105 | $img->Line(3, $h - 7, $w - 5, $h - 7); |
||
| 106 | |||
| 107 | // Window title |
||
| 108 | $m = floor($w / 2 - 5); |
||
| 109 | $l = 110; |
||
| 110 | $img->SetColor('lightgray:1.3'); |
||
| 111 | $img->FilledRectangle($m - $l, 2, $m + $l, 16); |
||
| 112 | |||
| 113 | // Stroke text |
||
| 114 | $img->SetColor('darkred'); |
||
| 115 | $img->SetFont(FF_FONT2, FS_BOLD); |
||
| 116 | $img->StrokeText($m - 90, 15, $this->iTitle); |
||
| 117 | $img->SetColor('black'); |
||
| 118 | $img->SetFont(FF_FONT1, FS_NORMAL); |
||
| 119 | $txt = new Text\Text($aMsg, 52, 25); |
||
| 120 | $txt->SetFont(FF_FONT1); |
||
| 121 | $txt->Align('left', 'top'); |
||
| 122 | $txt->Stroke($img); |
||
| 123 | if ($this->iDest) { |
||
| 124 | $img->Stream($this->iDest); |
||
| 125 | } else { |
||
| 126 | $img->Headers(); |
||
| 127 | $img->Stream(); |
||
| 128 | } |
||
| 129 | if ($aHalt) { |
||
| 130 | die(); |
||
| 131 | } |
||
| 134 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.