Conditions | 28 |
Paths | 684 |
Total Lines | 105 |
Code Lines | 64 |
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 namespace EvolutionCMS\Support; |
||
92 | public function render() { |
||
93 | $modx = evolutionCMS(); global $_PAGE; |
||
94 | |||
95 | $isDataset = $modx->getDatabase()->isResult($this->ds); |
||
96 | |||
97 | if(!$this->selPageStyle) { |
||
98 | $this->selPageStyle = "font-weight:bold"; |
||
99 | } |
||
100 | |||
101 | // get total number of rows |
||
102 | $tnr = ($isDataset) ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
||
103 | |||
104 | // render: no records found |
||
105 | if($tnr <= 0) { |
||
106 | $fnc = $this->renderRowFnc; |
||
107 | $args = $this->renderRowFncArgs; |
||
108 | if(isset($fnc)) { |
||
109 | if($args != "") { |
||
110 | $this->rows .= $fnc(0, null, $args); |
||
111 | } // if agrs was specified then we will pass three params |
||
112 | else { |
||
113 | $this->rows .= $fnc(0, null); |
||
114 | } // otherwise two will be passed |
||
115 | } |
||
116 | return; |
||
117 | } |
||
118 | |||
119 | // get total pages |
||
120 | $tp = ceil($tnr / $this->pageSize); |
||
121 | if($this->pageNumber > $tp) { |
||
122 | $this->pageNumber = 1; |
||
123 | } |
||
124 | |||
125 | // get page number |
||
126 | $p = $this->pageNumber; |
||
127 | |||
128 | // save page number to view state if available |
||
129 | if(isset($_PAGE['vs'])) { |
||
130 | $_PAGE['vs'][$this->id . '_dpgn'] = $p; |
||
131 | } |
||
132 | |||
133 | // render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments=""); |
||
134 | if($tp > 1) { |
||
135 | $url = ''; |
||
136 | $fnc = $this->renderPagerFnc; |
||
137 | $args = $this->renderPagerFncArgs; |
||
138 | if(!isset($fnc)) { |
||
139 | if($modx->isFrontend()) { |
||
140 | $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?'; |
||
141 | } else { |
||
142 | $url = $_SERVER['PHP_SELF'] . '?'; |
||
143 | } |
||
144 | $i = 0; |
||
145 | foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) { |
||
146 | $i++; |
||
147 | $url .= (($i > 1) ? "&" : "") . "$n=$v"; |
||
148 | } |
||
149 | if($i >= 1) { |
||
150 | $url .= "&"; |
||
151 | } |
||
152 | } |
||
153 | for($i = 1; $i <= $tp; $i++) { |
||
154 | if(isset($fnc)) { |
||
155 | if($args != "") { |
||
156 | $this->pager .= $fnc($p, $i, $args); |
||
157 | } else { |
||
158 | $this->pager .= $fnc($p, $i); |
||
159 | } |
||
160 | } else { |
||
161 | $this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> "; |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | |||
166 | // render row : renderRowFnc($rowNumber,$row,$arguments="") |
||
167 | $fnc = $this->renderRowFnc; |
||
168 | $args = $this->renderRowFncArgs; |
||
169 | |||
170 | if(isset($fnc)) { |
||
171 | $i = 1; |
||
172 | $fncObject = is_object($fnc); |
||
173 | $minitems = (($p - 1) * $this->pageSize) + 1; |
||
174 | $maxitems = (($p - 1) * $this->pageSize) + $this->pageSize; |
||
175 | while($i <= $maxitems && ($row = ($isDataset) ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$i - 1])) { |
||
176 | if($i >= $minitems && $i <= $maxitems) { |
||
177 | if($fncObject) { |
||
178 | if($args != "") { |
||
179 | $this->rows .= $fnc->RenderRowFnc($i, $row, $args); |
||
180 | } else { |
||
181 | $this->rows .= $fnc->RenderRowFnc($i, $row); |
||
182 | } |
||
183 | } else { |
||
184 | if($args != "") { |
||
185 | $this->rows .= $fnc($i, $row, $args); |
||
186 | } // if agrs was specified then we wil pass three params |
||
187 | else { |
||
188 | $this->rows .= $fnc($i, $row); |
||
189 | } // otherwise two will be passed |
||
190 | } |
||
191 | |||
192 | } |
||
193 | $i++; |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 |