Conditions | 6 |
Paths | 9 |
Total Lines | 54 |
Code Lines | 31 |
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 |
||
14 | public function list($keywordID, Carbon $fromDate, Carbon $toDate) : Collection |
||
15 | { |
||
16 | |||
17 | $start = 0; |
||
18 | $rankings = collect(); |
||
19 | |||
20 | do { |
||
21 | $response = $this->performQuery('rankings/list', ['keyword_id' => $keywordID, 'from_date' => $fromDate->toDateString(), 'to_date' => $toDate->toDateString(), 'start' => 0]); |
||
22 | $start += 30; |
||
23 | |||
24 | if($response['totalresults'] == 0) { |
||
25 | break; |
||
26 | } |
||
27 | |||
28 | if($response['totalresults'] == 1) { |
||
29 | $rankings->push($response['Result']); |
||
30 | } |
||
31 | |||
32 | if($response['totalresults'] > 1) { |
||
33 | $rankings = $rankings->merge($response['Result']); |
||
34 | } |
||
35 | |||
36 | |||
37 | if (!isset($response['nextpage'])) { |
||
38 | break; |
||
39 | } |
||
40 | |||
41 | } while ($response['resultsreturned'] < $response['totalresults']); |
||
42 | |||
43 | |||
44 | $rankings = $rankings->transform(function ($ranking, $key) { |
||
|
|||
45 | |||
46 | return new StatKeywordRanking([ |
||
47 | 'date' => $ranking['date'], |
||
48 | 'google' => new StatKeywordEngineRanking([ |
||
49 | 'rank' => $ranking['Google']['Rank'], |
||
50 | 'base_rank' => $ranking['Google']['BaseRank'], |
||
51 | 'url' => $ranking['Google']['Url'] ?? '', |
||
52 | ]), |
||
53 | 'yahoo' => new StatKeywordEngineRanking([ |
||
54 | 'rank' => $ranking['Yahoo']['Rank'], |
||
55 | 'url' => $ranking['Yahoo']['Url'] ?? '', |
||
56 | 'base_rank' => $ranking['Yahoo']['BaseRank'], |
||
57 | ]), |
||
58 | 'bing' => new StatKeywordEngineRanking([ |
||
59 | 'rank' => $ranking['Bing']['Rank'], |
||
60 | 'url' => $ranking['Bing']['Url'] ?? '', |
||
61 | 'base_rank' => $ranking['Bing']['BaseRank'], |
||
62 | ]), |
||
63 | ]); |
||
64 | }); |
||
65 | |||
66 | return $rankings; |
||
67 | } |
||
68 | |||
73 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.