Conditions | 14 |
Paths | 200 |
Total Lines | 109 |
Lines | 4 |
Ratio | 3.67 % |
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 |
||
89 | public function getData(&$overview) |
||
90 | { |
||
91 | $this->output->writeln("\t" . 'Fetching goals..'); |
||
92 | |||
93 | // calculate timespan |
||
94 | $timespan = $overview->getTimespan() - $overview->getStartOffset(); |
||
95 | if ($timespan <= 1) { |
||
96 | $extra = array('dimensions' => 'ga:date,ga:hour'); |
||
97 | $start = 2; |
||
98 | } else { |
||
99 | if ($timespan <= 7) { |
||
100 | $extra = array('dimensions' => 'ga:date,ga:hour'); |
||
101 | $start = 2; |
||
102 | } else { |
||
103 | if ($timespan <= 31) { |
||
104 | $extra = array('dimensions' => 'ga:week,ga:day,ga:date'); |
||
105 | $start = 3; |
||
106 | } else { |
||
107 | $extra = array('dimensions' => 'ga:isoYearIsoWeek'); |
||
108 | $start = 1; |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | // add segment |
||
114 | if ($overview->getSegment()) { |
||
115 | $extra['segment'] = $overview->getSegment()->getQuery(); |
||
116 | } |
||
117 | |||
118 | $goals = $this->getAllGoals(); |
||
119 | if (!$goals) { |
||
120 | return; |
||
121 | } |
||
122 | $goaldata = array(); |
||
123 | |||
124 | // Create an array with for each goal an entry to create the metric parameter. |
||
125 | foreach ($goals as $key => $value) { |
||
126 | ++$key; |
||
127 | $goaldata[] = array('position' => $key, 'name' => $value->name); |
||
128 | } |
||
129 | |||
130 | $metrics = $this->prepareMetrics(); |
||
131 | |||
132 | $rows = $this->requestGoalResults($overview, $metrics[0], $extra); |
||
133 | // Execute an extra query if there are more than 10 goals to query |
||
134 | if (count($metrics) > 1) { |
||
135 | $rows2 = $this->requestGoalResults($overview, $metrics[1], $extra); |
||
136 | $rows2size = count($rows2); |
||
137 | for ($i = 0; $i < $rows2size; ++$i) { |
||
138 | // Merge the results of the extra query data with the previous query data. |
||
139 | $rows[$i] = array_merge($rows[$i], array_slice($rows2[$i], $start, count($rows2) - $start)); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | // Create a result array to be parsed and create Goal objects from |
||
144 | $goalCollection = array(); |
||
145 | $goaldatasize = count($goaldata); |
||
146 | for ($i = 0; $i < $goaldatasize; ++$i) { |
||
147 | $goalEntry = array(); |
||
148 | foreach ($rows as $row) { |
||
149 | // Create a timestamp for each goal visit (this depends on the timespan of the overview: split per hour, day, week, month) |
||
150 | if ($timespan <= 1) { |
||
151 | $timestamp = mktime( |
||
152 | $row[1], |
||
153 | 0, |
||
154 | 0, |
||
155 | substr($row[0], 4, 2), |
||
156 | substr($row[0], 6, 2), |
||
157 | substr($row[0], 0, 4) |
||
158 | ); |
||
159 | $timestamp = date('Y-m-d H:00', $timestamp); |
||
160 | } else { |
||
161 | if ($timespan <= 7) { |
||
162 | $timestamp = mktime( |
||
163 | $row[1], |
||
164 | 0, |
||
165 | 0, |
||
166 | substr($row[0], 4, 2), |
||
167 | substr($row[0], 6, 2), |
||
168 | substr($row[0], 0, 4) |
||
169 | ); |
||
170 | $timestamp = date('Y-m-d H:00', $timestamp); |
||
171 | } else { |
||
172 | if ($timespan <= 31) { |
||
173 | $timestamp = mktime( |
||
174 | 0, |
||
175 | 0, |
||
176 | 0, |
||
177 | substr($row[2], 4, 2), |
||
178 | substr($row[2], 6, 2), |
||
179 | substr($row[2], 0, 4) |
||
180 | ); |
||
181 | $timestamp = date('Y-m-d H:00', $timestamp); |
||
182 | View Code Duplication | } else { |
|
183 | $timestamp = strtotime(substr($row[0], 0, 4) . 'W' . substr($row[0], 4, 2)); |
||
184 | $timestamp = date('Y-m-d H:00', $timestamp); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | $goalEntry[$timestamp] = $row[$i + $start]; |
||
189 | } |
||
190 | $goalCollection['goal' . $goaldata[$i]['position']]['name'] = $goaldata[$i]['name']; |
||
191 | $goalCollection['goal' . $goaldata[$i]['position']]['position'] = $goaldata[$i]['position']; |
||
192 | $goalCollection['goal' . $goaldata[$i]['position']]['visits'] = $goalEntry; |
||
193 | } |
||
194 | |||
195 | // Parse the goals and append them to the overview. |
||
196 | $this->parseGoals($overview, $goalCollection); |
||
197 | } |
||
198 | |||
254 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.