Conditions | 17 |
Paths | 800 |
Total Lines | 75 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
87 | public function Addons() { |
||
88 | $list = Addon::get(); |
||
89 | |||
90 | $search = $this->request->getVar('search'); |
||
91 | $type = $this->request->getVar('type'); |
||
92 | $compat = $this->request->getVar('compatibility'); |
||
93 | $tags = $this->request->getVar('tags'); |
||
94 | $sort = $this->request->getVar('sort'); |
||
95 | $view = $this->request->getVar('view'); |
||
96 | |||
97 | if (!$view) { |
||
98 | $view = 'list'; |
||
|
|||
99 | } |
||
100 | |||
101 | if (!in_array($sort, array('name', 'downloads', 'newest'))) { |
||
102 | $sort = null; |
||
103 | } |
||
104 | |||
105 | // Proxy out a search to elastic if any parameters are set. |
||
106 | if ($search || $type || $compat || $tags) { |
||
107 | |||
108 | $bool = new Query\BoolQuery(); |
||
109 | |||
110 | $query = new Query(); |
||
111 | $query->setQuery($bool); |
||
112 | $query->setSize(count($list)); |
||
113 | |||
114 | |||
115 | if ($search) { |
||
116 | $match = new Match(); |
||
117 | $match->setField('_all', $search); |
||
118 | |||
119 | $bool->addMust($match); |
||
120 | } |
||
121 | |||
122 | if ($type) { |
||
123 | $bool->addMust(new Query\Term(array('type' => $type))); |
||
124 | } |
||
125 | |||
126 | if ($compat) { |
||
127 | $bool->addMust(new Query\Terms('compatibility', (array) $compat)); |
||
128 | } |
||
129 | |||
130 | if ($tags) { |
||
131 | $bool->addMust(new Query\Terms('tag', (array) $tags)); |
||
132 | } |
||
133 | |||
134 | $list = new ResultList($this->elastica->getIndex(), $query); |
||
135 | |||
136 | if ($sort) { |
||
137 | $ids = $list->column('ID'); |
||
138 | |||
139 | if ($ids) { |
||
140 | $list = Addon::get()->byIDs($ids); |
||
141 | } else { |
||
142 | $list = new ArrayList(); |
||
143 | } |
||
144 | } else { |
||
145 | $list = $list->toArrayList(); |
||
146 | } |
||
147 | } else { |
||
148 | if (!$sort) $sort = 'downloads'; |
||
149 | } |
||
150 | |||
151 | switch ($sort) { |
||
152 | case 'name': $list = $list->sort('Name'); break; |
||
153 | case 'newest': $list = $list->sort('Released', 'DESC'); break; |
||
154 | case 'downloads': $list = $list->sort('Downloads', 'DESC'); break; |
||
155 | } |
||
156 | |||
157 | $list = new PaginatedList($list, $this->request); |
||
158 | $list->setPageLength(16); |
||
159 | |||
160 | return $list; |
||
161 | } |
||
162 | |||
218 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.