| Total Complexity | 126 |
| Total Lines | 561 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like GTextTableCell often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GTextTableCell, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class GTextTableCell |
||
| 35 | { |
||
| 36 | public $iColSpan = 1; |
||
| 37 | public $iRowSpan = 1; |
||
| 38 | public $iMarginLeft = 5; |
||
| 39 | public $iMarginRight = 5; |
||
| 40 | public $iMarginTop = 5; |
||
| 41 | public $iMarginBottom = 5; |
||
| 42 | public $iVal; |
||
| 43 | private $iBGColor = ''; |
||
| 44 | private $iFontColor = 'black'; |
||
| 45 | private $iFF = FF_FONT1; |
||
| 46 | private $iFS = FS_NORMAL; |
||
| 47 | private $iFSize = 10; |
||
| 48 | private $iRow = 0; |
||
| 49 | private $iCol = 0; |
||
| 50 | private $iVertAlign = 'bottom'; |
||
| 51 | private $iHorAlign = 'left'; |
||
| 52 | private $iMerged = false; |
||
| 53 | private $iPRow; |
||
| 54 | private $iPCol; |
||
| 55 | private $iTable; |
||
| 56 | private $iGridColor = ['darkgray', 'darkgray', 'darkgray', 'darkgray']; |
||
| 57 | private $iGridWeight = [1, 1, 0, 0]; // left,top,bottom,right; |
||
| 58 | private $iGridStyle = [TGRID_SINGLE, TGRID_SINGLE, TGRID_SINGLE, TGRID_SINGLE]; // left,top,bottom,right; |
||
| 59 | private $iNumberFormat; |
||
| 60 | private $iIcon; |
||
| 61 | private $iIconConstrain = []; |
||
| 62 | private $iCSIMtarget = ''; |
||
| 63 | private $iCSIMwintarget = ''; |
||
| 64 | private $iCSIMalt = ''; |
||
| 65 | private $iCSIMArea = ''; |
||
| 66 | |||
| 67 | public function __construct($aVal = '', $aRow = 0, $aCol = 0) |
||
| 68 | { |
||
| 69 | $this->iVal = new Text($aVal); |
||
| 70 | $this->iRow = $aRow; |
||
| 71 | $this->iCol = $aCol; |
||
| 72 | $this->iPRow = $aRow; // Initialiy each cell is its own parent |
||
| 73 | $this->iPCol = $aCol; |
||
| 74 | $this->iIconConstrain = [-1, -1]; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function Init($aTable) |
||
| 78 | { |
||
| 79 | $this->iTable = $aTable; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function SetCSIMTarget($aTarget, $aAlt = '', $aWinTarget = '') |
||
| 83 | { |
||
| 84 | $this->iCSIMtarget = $aTarget; |
||
| 85 | $this->iCSIMwintarget = $aWinTarget; |
||
| 86 | $this->iCSIMalt = $aAlt; |
||
| 87 | } |
||
| 88 | |||
| 89 | public function GetCSIMArea() |
||
| 90 | { |
||
| 91 | if ($this->iCSIMtarget !== '') { |
||
| 92 | return $this->iCSIMArea; |
||
| 93 | } |
||
| 94 | |||
| 95 | return ''; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function SetImageConstrain($aType, $aVal) |
||
| 99 | { |
||
| 100 | if (!in_array($aType, [TIMG_WIDTH, TIMG_HEIGHT], true)) { |
||
| 101 | Util\JpGraphError::RaiseL(27015); |
||
| 102 | } |
||
| 103 | $this->iIconConstrain = [$aType, $aVal]; |
||
| 104 | } |
||
| 105 | |||
| 106 | public function SetCountryFlag($aFlag, $aScale = 1.0, $aMix = 100, $aStdSize = 3) |
||
| 107 | { |
||
| 108 | $this->iIcon = new Plot\IconPlot(); |
||
| 109 | $this->iIcon->SetCountryFlag($aFlag, 0, 0, $aScale, $aMix, $aStdSize); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function SetImage($aFile, $aScale = 1.0, $aMix = 100) |
||
| 113 | { |
||
| 114 | $this->iIcon = new Plot\IconPlot($aFile, 0, 0, $aScale, $aMix); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function SetImageFromString($aStr, $aScale = 1.0, $aMix = 100) |
||
| 118 | { |
||
| 119 | $this->iIcon = new Plot\IconPlot('', 0, 0, $aScale, $aMix); |
||
| 120 | $this->iIcon->CreateFromString($aStr); |
||
| 121 | } |
||
| 122 | |||
| 123 | public function SetRowColSpan($aRowSpan, $aColSpan) |
||
| 128 | } |
||
| 129 | |||
| 130 | public function SetMerged($aPRow, $aPCol, $aFlg = true) |
||
| 131 | { |
||
| 132 | $this->iMerged = $aFlg; |
||
| 133 | $this->iPRow = $aPRow; |
||
| 134 | $this->iPCol = $aPCol; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function IsMerged() |
||
| 138 | { |
||
| 139 | return $this->iMerged; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function SetNumberFormat($aF) |
||
| 145 | } |
||
| 146 | |||
| 147 | public function Set($aTxt) |
||
| 148 | { |
||
| 149 | $this->iVal->Set($aTxt); |
||
| 150 | } |
||
| 151 | |||
| 152 | public function SetFont($aFF, $aFS, $aFSize) |
||
| 153 | { |
||
| 154 | $this->iFF = $aFF; |
||
| 155 | $this->iFS = $aFS; |
||
| 156 | $this->iFSize = $aFSize; |
||
| 157 | $this->iVal->SetFont($aFF, $aFS, $aFSize); |
||
| 158 | } |
||
| 159 | |||
| 160 | public function SetFillColor($aColor) |
||
| 161 | { |
||
| 162 | $this->iBGColor = $aColor; |
||
| 163 | } |
||
| 164 | |||
| 165 | public function SetFontColor($aColor) |
||
| 166 | { |
||
| 167 | $this->iFontColor = $aColor; |
||
| 168 | } |
||
| 169 | |||
| 170 | public function SetGridColor($aLeft, $aTop = null, $aBottom = null, $aRight = null) |
||
| 171 | { |
||
| 172 | if ($aLeft !== null) { |
||
| 173 | $this->iGridColor[0] = $aLeft; |
||
| 174 | } |
||
| 175 | |||
| 176 | if ($aTop !== null) { |
||
| 177 | $this->iGridColor[1] = $aTop; |
||
| 178 | } |
||
| 179 | |||
| 180 | if ($aBottom !== null) { |
||
| 181 | $this->iGridColor[2] = $aBottom; |
||
| 182 | } |
||
| 183 | |||
| 184 | if ($aRight !== null) { |
||
| 185 | $this->iGridColor[3] = $aRight; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | public function SetGridStyle($aLeft, $aTop = null, $aBottom = null, $aRight = null) |
||
| 190 | { |
||
| 191 | if ($aLeft !== null) { |
||
| 192 | $this->iGridStyle[0] = $aLeft; |
||
| 193 | } |
||
| 194 | |||
| 195 | if ($aTop !== null) { |
||
| 196 | $this->iGridStyle[1] = $aTop; |
||
| 197 | } |
||
| 198 | |||
| 199 | if ($aBottom !== null) { |
||
| 200 | $this->iGridStyle[2] = $aBottom; |
||
| 201 | } |
||
| 202 | |||
| 203 | if ($aRight !== null) { |
||
| 204 | $this->iGridStyle[3] = $aRight; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | public function SetGridWeight($aLeft = null, $aTop = null, $aBottom = null, $aRight = null) |
||
| 209 | { |
||
| 210 | if ($aLeft !== null) { |
||
| 211 | $this->iGridWeight[0] = $aLeft; |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($aTop !== null) { |
||
| 215 | $this->iGridWeight[1] = $aTop; |
||
| 216 | } |
||
| 217 | |||
| 218 | if ($aBottom !== null) { |
||
| 219 | $this->iGridWeight[2] = $aBottom; |
||
| 220 | } |
||
| 221 | |||
| 222 | if ($aRight !== null) { |
||
| 223 | $this->iGridWeight[3] = $aRight; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | public function SetMargin($aLeft, $aRight, $aTop, $aBottom) |
||
| 228 | { |
||
| 229 | $this->iMarginLeft = $aLeft; |
||
| 230 | $this->iMarginRight = $aRight; |
||
| 231 | $this->iMarginTop = $aTop; |
||
| 232 | $this->iMarginBottom = $aBottom; |
||
| 233 | } |
||
| 234 | |||
| 235 | public function GetWidth($aImg) |
||
| 236 | { |
||
| 237 | if ($this->iIcon !== null) { |
||
| 238 | if ($this->iIconConstrain[0] == TIMG_WIDTH) { |
||
| 239 | $this->iIcon->SetScale(1); |
||
| 240 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 241 | $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[0]); |
||
| 242 | } elseif ($this->iIconConstrain[0] == TIMG_HEIGHT) { |
||
| 243 | $this->iIcon->SetScale(1); |
||
| 244 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 245 | $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[1]); |
||
| 246 | } |
||
| 247 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 248 | $iwidth = $tmp[0]; |
||
| 249 | } else { |
||
| 250 | $iwidth = 0; |
||
| 251 | } |
||
| 252 | if ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0) { |
||
| 253 | $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg); |
||
| 254 | } elseif ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 90) { |
||
| 255 | $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetFontHeight($aImg) + 2; |
||
| 256 | } else { |
||
| 257 | $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg) + 2; |
||
| 258 | } |
||
| 259 | |||
| 260 | $pcolspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iColSpan; |
||
| 261 | |||
| 262 | return round(max($iwidth, $pwidth) / $pcolspan) + $this->iMarginLeft + $this->iMarginRight; |
||
| 263 | } |
||
| 264 | |||
| 265 | public function GetHeight($aImg) |
||
| 266 | { |
||
| 267 | if ($this->iIcon !== null) { |
||
| 268 | if ($this->iIconConstrain[0] == TIMG_WIDTH) { |
||
| 269 | $this->iIcon->SetScale(1); |
||
| 270 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 271 | $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[0]); |
||
| 272 | } elseif ($this->iIconConstrain[0] == TIMG_HEIGHT) { |
||
| 273 | $this->iIcon->SetScale(1); |
||
| 274 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 275 | $this->iIcon->SetScale($this->iIconConstrain[1] / $tmp[1]); |
||
| 276 | } |
||
| 277 | $tmp = $this->iIcon->GetWidthHeight(); |
||
| 278 | $iheight = $tmp[1]; |
||
| 279 | } else { |
||
| 280 | $iheight = 0; |
||
| 281 | } |
||
| 282 | if ($this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0) { |
||
| 283 | $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg); |
||
| 284 | } else { |
||
| 285 | $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg) + 1; |
||
| 286 | } |
||
| 287 | $prowspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iRowSpan; |
||
| 288 | |||
| 289 | return round(max($iheight, $pheight) / $prowspan) + $this->iMarginTop + $this->iMarginBottom; |
||
| 290 | } |
||
| 291 | |||
| 292 | public function SetAlign($aHorAlign = 'left', $aVertAlign = 'bottom') |
||
| 302 | } |
||
| 303 | |||
| 304 | public function AdjustMarginsForGrid() |
||
| 305 | { |
||
| 306 | if ($this->iCol > 0) { |
||
| 307 | switch ($this->iGridStyle[0]) { |
||
| 308 | case TGRID_SINGLE: |
||
| 309 | $wf = 1; |
||
| 310 | |||
| 311 | break; |
||
| 312 | case TGRID_DOUBLE: |
||
| 313 | $wf = 3; |
||
| 314 | |||
| 315 | break; |
||
| 316 | case TGRID_DOUBLE2: |
||
| 317 | $wf = 4; |
||
| 318 | |||
| 319 | break; |
||
| 320 | } |
||
| 321 | $this->iMarginLeft += $this->iGridWeight[0] * $wf; |
||
|
|
|||
| 322 | } |
||
| 323 | if ($this->iRow > 0) { |
||
| 324 | switch ($this->iGridStyle[1]) { |
||
| 325 | case TGRID_SINGLE: |
||
| 326 | $wf = 1; |
||
| 327 | |||
| 328 | break; |
||
| 329 | case TGRID_DOUBLE: |
||
| 330 | $wf = 3; |
||
| 331 | |||
| 332 | break; |
||
| 333 | case TGRID_DOUBLE2: |
||
| 334 | $wf = 4; |
||
| 335 | |||
| 336 | break; |
||
| 337 | } |
||
| 338 | $this->iMarginTop += $this->iGridWeight[1] * $wf; |
||
| 339 | } |
||
| 340 | if ($this->iRow + $this->iRowSpan - 1 < $this->iTable->iSize[0] - 1) { |
||
| 341 | switch ($this->iGridStyle[2]) { |
||
| 342 | case TGRID_SINGLE: |
||
| 343 | $wf = 1; |
||
| 344 | |||
| 345 | break; |
||
| 346 | case TGRID_DOUBLE: |
||
| 347 | $wf = 3; |
||
| 348 | |||
| 349 | break; |
||
| 350 | case TGRID_DOUBLE2: |
||
| 351 | $wf = 4; |
||
| 352 | |||
| 353 | break; |
||
| 354 | } |
||
| 355 | $this->iMarginBottom += $this->iGridWeight[2] * $wf; |
||
| 356 | } |
||
| 357 | if ($this->iCol + $this->iColSpan - 1 < $this->iTable->iSize[1] - 1) { |
||
| 358 | switch ($this->iGridStyle[3]) { |
||
| 359 | case TGRID_SINGLE: |
||
| 360 | $wf = 1; |
||
| 361 | |||
| 362 | break; |
||
| 363 | case TGRID_DOUBLE: |
||
| 364 | $wf = 3; |
||
| 365 | |||
| 366 | break; |
||
| 367 | case TGRID_DOUBLE2: |
||
| 368 | $wf = 4; |
||
| 369 | |||
| 370 | break; |
||
| 371 | } |
||
| 372 | $this->iMarginRight += $this->iGridWeight[3] * $wf; |
||
| 373 | } |
||
| 374 | } |
||
| 375 | |||
| 376 | public function StrokeVGrid($aImg, $aX, $aY, $aWidth, $aHeight, $aDir = 1) |
||
| 377 | { |
||
| 378 | // Left or right grid line |
||
| 379 | // For the right we increase the X-pos and for the right we decrease it. This is |
||
| 380 | // determined by the direction argument. |
||
| 381 | $idx = $aDir == 1 ? 0 : 3; |
||
| 382 | |||
| 383 | // We don't stroke the grid lines that are on the edge of the table since this is |
||
| 384 | // the place of the border. |
||
| 385 | if ((($this->iCol > 0 && $idx == 0) || ($this->iCol + $this->iColSpan - 1 < $this->iTable->iSize[1] - 1 && $idx == 3)) |
||
| 386 | && $this->iGridWeight[$idx] > 0) { |
||
| 387 | $x = $aDir == 1 ? $aX : $aX + $aWidth - 1; |
||
| 388 | $y = $aY + $aHeight - 1; |
||
| 389 | $aImg->SetColor($this->iGridColor[$idx]); |
||
| 390 | switch ($this->iGridStyle[$idx]) { |
||
| 391 | case TGRID_SINGLE: |
||
| 392 | for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) { |
||
| 393 | $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y); |
||
| 394 | } |
||
| 395 | |||
| 396 | break; |
||
| 397 | case TGRID_DOUBLE: |
||
| 398 | for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) { |
||
| 399 | $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y); |
||
| 400 | } |
||
| 401 | |||
| 402 | $x += $this->iGridWeight[$idx] * 2; |
||
| 403 | for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) { |
||
| 404 | $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y); |
||
| 405 | } |
||
| 406 | |||
| 407 | break; |
||
| 408 | case TGRID_DOUBLE2: |
||
| 409 | for ($i = 0; $i < $this->iGridWeight[$idx] * 2; ++$i) { |
||
| 410 | $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y); |
||
| 411 | } |
||
| 412 | |||
| 413 | $x += $this->iGridWeight[$idx] * 3; |
||
| 414 | for ($i = 0; $i < $this->iGridWeight[$idx]; ++$i) { |
||
| 415 | $aImg->Line($x + $i * $aDir, $aY, $x + $i * $aDir, $y); |
||
| 416 | } |
||
| 417 | |||
| 418 | break; |
||
| 419 | } |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | public function StrokeHGrid($aImg, $aX, $aY, $aWidth, $aHeight, $aDir = 1) |
||
| 466 | } |
||
| 467 | } |
||
| 468 | } |
||
| 469 | |||
| 470 | public function Stroke($aImg, $aX, $aY, $aWidth, $aHeight) |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | /* |
||
| 599 | EOF |
||
| 600 | */ |
||
| 601 |