Total Complexity | 40 |
Total Lines | 203 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like JvectorMap 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 JvectorMap, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class JvectorMap extends Widget |
||
31 | { |
||
32 | /** @var string jvpath js map **/ |
||
33 | public $jvpath = '@cjtterabytesoft/widget/jvectormap/assets/maps/js/'; |
||
34 | |||
35 | /** @var string jvpathcustom js map **/ |
||
36 | public $jvpathcustom = '@webroot/maps/js/'; |
||
37 | |||
38 | /** @var string $jvname js map **/ |
||
39 | public $jvname = 'jquery-jvectormap-'; |
||
40 | |||
41 | /** @var integer $jverror js map **/ |
||
42 | public $jverror = 0; |
||
43 | |||
44 | /** @var string $jvimage404 js map **/ |
||
45 | public $jvimage404 = '/images/errors/404-map.png'; |
||
46 | |||
47 | /** @var string $jvimage500 js map **/ |
||
48 | public $jvimage500 = '/images/errors/500-map.png'; |
||
49 | |||
50 | /** AssetBundle Dinamic **/ |
||
51 | public $bundle; |
||
52 | |||
53 | /** @var string tag container **/ |
||
54 | public $tag = 'div'; |
||
55 | |||
56 | /** @var string $id [div] [$id - function Jquery.JVectorMap] **/ |
||
57 | public $id; |
||
58 | |||
59 | /** @var array [div - $htmlOptions[$style]] **/ |
||
60 | public $style = []; |
||
61 | |||
62 | /** @var array [div - $htmlOptions] **/ |
||
63 | public $htmlOptions = []; |
||
64 | |||
65 | /** @var string [$map] **/ |
||
66 | public $map; |
||
67 | |||
68 | /** @var boolean jvdefault js map **/ |
||
69 | public $maptype = false; |
||
70 | |||
71 | /** @var string [$config function Jquery.JVectorMap] **/ |
||
72 | public $config; |
||
73 | |||
74 | /** @var string [$backgroundColor] **/ |
||
75 | public $backgroundColor; |
||
76 | |||
77 | /** @var string [$focusOn] **/ |
||
78 | public $focusOn = []; |
||
79 | |||
80 | /** @var array [$labels] **/ |
||
81 | public $labels = []; |
||
82 | |||
83 | /** @var array [$markerLabelStyle] **/ |
||
84 | public $markerLabelStyle = []; |
||
85 | |||
86 | /** @var array [$markers] **/ |
||
87 | public $markers = []; |
||
88 | |||
89 | /** @var boolean [$markersSelectable] **/ |
||
90 | public $markersSelectable = false; |
||
91 | |||
92 | /** @var boolean [$markersSelectableOne] **/ |
||
93 | public $markersSelectableOne = false; |
||
94 | |||
95 | /** @var array [$markerStyle] **/ |
||
96 | public $markerStyle = []; |
||
97 | |||
98 | /** @var boolean [$panOnDrag] **/ |
||
99 | public $panOnDrag = true; |
||
100 | |||
101 | /** @var array [$regionLabelStyle] **/ |
||
102 | public $regionLabelStyle = []; |
||
103 | |||
104 | /** @var boolean [$regionsSelectable] **/ |
||
105 | public $regionsSelectable = true; |
||
106 | |||
107 | /** @var boolean [$regionsSelectableOne] **/ |
||
108 | public $regionsSelectableOne = false; |
||
109 | |||
110 | /** @var array [$regionStyle] **/ |
||
111 | public $regionStyle = []; |
||
112 | |||
113 | /** @var array [$selectedMarkers] **/ |
||
114 | public $selectedMarkers = []; |
||
115 | |||
116 | /** @var array [$selectedRegions] **/ |
||
117 | public $selectedRegions = []; |
||
118 | |||
119 | /** @var array [$series] **/ |
||
120 | public $series = []; |
||
121 | |||
122 | /** @var boolean [$zoomAnimate] **/ |
||
123 | public $zoomAnimate = false; |
||
124 | |||
125 | /** @var integer [$zoomMax] **/ |
||
126 | public $zoomMax; |
||
127 | |||
128 | /** @var integer [$zoomMin] **/ |
||
129 | public $zoomMin; |
||
130 | |||
131 | /** @var boolean [$zoomOnScroll] **/ |
||
132 | public $zoomOnScroll = true; |
||
133 | |||
134 | public function init() |
||
135 | { |
||
136 | parent::init(); |
||
137 | if (!file_exists(\Yii::getAlias('@webroot/images/errors/'))) { |
||
138 | BaseFileHelper::copyDirectory(\Yii::getAlias('@cjtterabytesoft/widget/jvectormap/images/errors'), |
||
139 | \Yii::getAlias('@frontend/web/images/errors')); |
||
140 | } |
||
141 | if (empty($this->id)) { |
||
142 | $this->id = 'vmap'; |
||
143 | } |
||
144 | $this->htmlOptions['id'] = $this->id; |
||
145 | $this->htmlOptions['style'] = $this->style; |
||
146 | if (empty($this->map)) { |
||
147 | $this->jverror = 1; |
||
148 | } else { |
||
149 | $this->MapJs(); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | public function run() |
||
199 | } |
||
200 | } |
||
201 | |||
202 | public function MapJs() { |
||
203 | $this->jvname = $this->jvname . str_replace('_', '-', $this->map) . ".js"; |
||
204 | if (file_exists(yii::getAlias((!$this->maptype ? $this->jvpath : $this->jvpathcustom) . $this->jvname))) { |
||
205 | JvectorMapAsset::register(Yii::$app->view); |
||
206 | $this->bundle = !$this->maptype ? MapAsset::register(Yii::$app->view) : |
||
207 | MapCustomAsset::register(Yii::$app->view); |
||
208 | $this->bundle->js[] = $this->jvname; // dynamic map added |
||
209 | $this->bundle->publishOptions[] = [ |
||
210 | 'only' => [ |
||
211 | yii::getalias((!$this->maptype ? $this->jvpath : $this->jvpathcustom) . $this->jvname), |
||
212 | ] |
||
213 | ]; |
||
214 | } else { |
||
215 | $this->jverror = 2; |
||
216 | } |
||
217 | } |
||
218 | |||
219 | public function ErrorMap() { |
||
233 | } |
||
234 | } |
||
236 |