| Total Complexity | 47 |
| Total Lines | 296 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like GanttBar 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 GanttBar, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class GanttBar extends GanttPlotObject |
||
| 19 | { |
||
| 20 | public $progress; |
||
| 21 | public $leftMark; |
||
| 22 | public $rightMark; |
||
| 23 | private $iEnd; |
||
| 24 | private $iHeightFactor = 0.5; |
||
| 25 | private $iFillColor = 'white'; |
||
| 26 | private $iFrameColor = 'black'; |
||
| 27 | private $iShadow = false; |
||
| 28 | private $iShadowColor = 'darkgray'; |
||
| 29 | private $iShadowWidth = 1; |
||
| 30 | private $iShadowFrame = 'black'; |
||
|
|
|||
| 31 | private $iPattern = GANTT_RDIAG; |
||
| 32 | private $iPatternColor = 'blue'; |
||
| 33 | private $iPatternDensity = 95; |
||
| 34 | private $iBreakStyle = false; |
||
| 35 | private $iBreakLineStyle = 'dotted'; |
||
| 36 | private $iBreakLineWeight = 1; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * CONSTRUCTOR. |
||
| 40 | * |
||
| 41 | * @param mixed $aPos |
||
| 42 | * @param mixed $aLabel |
||
| 43 | * @param mixed $aStart |
||
| 44 | * @param mixed $aEnd |
||
| 45 | * @param mixed $aCaption |
||
| 46 | * @param mixed $aHeightFactor |
||
| 47 | */ |
||
| 48 | public function __construct($aPos, $aLabel, $aStart, $aEnd, $aCaption = '', $aHeightFactor = 0.6) |
||
| 49 | { |
||
| 50 | parent::__construct(); |
||
| 51 | $this->iStart = $aStart; |
||
| 52 | // Is the end date given as a date or as number of days added to start date? |
||
| 53 | if (is_string($aEnd)) { |
||
| 54 | // If end date has been specified without a time we will asssume |
||
| 55 | // end date is at the end of that date |
||
| 56 | if (strpos($aEnd, ':') === false) { |
||
| 57 | $this->iEnd = strtotime($aEnd) + SECPERDAY - 1; |
||
| 58 | } else { |
||
| 59 | $this->iEnd = $aEnd; |
||
| 60 | } |
||
| 61 | } elseif (is_int($aEnd) || is_float($aEnd)) { |
||
| 62 | $this->iEnd = strtotime($aStart) + round($aEnd * SECPERDAY); |
||
| 63 | } |
||
| 64 | $this->iVPos = $aPos; |
||
| 65 | $this->iHeightFactor = $aHeightFactor; |
||
| 66 | $this->title->Set($aLabel); |
||
| 67 | $this->caption = new Text\TextProperty($aCaption); |
||
| 68 | $this->caption->Align('left', 'center'); |
||
| 69 | $this->leftMark = new PlotMark(); |
||
| 70 | $this->leftMark->Hide(); |
||
| 71 | $this->rightMark = new PlotMark(); |
||
| 72 | $this->rightMark->Hide(); |
||
| 73 | $this->progress = new Image\Progress(); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * PUBLIC METHODS. |
||
| 78 | * |
||
| 79 | * @param mixed $aShadow |
||
| 80 | * @param mixed $aColor |
||
| 81 | */ |
||
| 82 | public function SetShadow($aShadow = true, $aColor = 'gray') |
||
| 83 | { |
||
| 84 | $this->iShadow = $aShadow; |
||
| 85 | $this->iShadowColor = $aColor; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function SetBreakStyle($aFlg = true, $aLineStyle = 'dotted', $aLineWeight = 1) |
||
| 89 | { |
||
| 90 | $this->iBreakStyle = $aFlg; |
||
| 91 | $this->iBreakLineStyle = $aLineStyle; |
||
| 92 | $this->iBreakLineWeight = $aLineWeight; |
||
| 93 | } |
||
| 94 | |||
| 95 | public function GetMaxDate() |
||
| 96 | { |
||
| 97 | return $this->iEnd; |
||
| 98 | } |
||
| 99 | |||
| 100 | public function SetHeight($aHeight) |
||
| 101 | { |
||
| 102 | $this->iHeightFactor = $aHeight; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function SetColor($aColor) |
||
| 108 | } |
||
| 109 | |||
| 110 | public function SetFillColor($aColor) |
||
| 111 | { |
||
| 112 | $this->iFillColor = $aColor; |
||
| 113 | } |
||
| 114 | |||
| 115 | public function GetAbsHeight($aImg) |
||
| 116 | { |
||
| 117 | if (is_int($this->iHeightFactor) || $this->leftMark->show || $this->rightMark->show) { |
||
| 118 | $m = -1; |
||
| 119 | if (is_int($this->iHeightFactor)) { |
||
| 120 | $m = $this->iHeightFactor; |
||
| 121 | } |
||
| 122 | |||
| 123 | if ($this->leftMark->show) { |
||
| 124 | $m = max($m, $this->leftMark->width * 2); |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($this->rightMark->show) { |
||
| 128 | $m = max($m, $this->rightMark->width * 2); |
||
| 129 | } |
||
| 130 | |||
| 131 | return $m; |
||
| 132 | } |
||
| 133 | |||
| 134 | return -1; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function SetPattern($aPattern, $aColor = 'blue', $aDensity = 95) |
||
| 142 | } |
||
| 143 | |||
| 144 | public function Stroke($aImg, $aScale) |
||
| 145 | { |
||
| 146 | $factory = new Graph\RectPatternFactory(); |
||
| 317 |