Conditions | 12 |
Paths | 90 |
Total Lines | 49 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
17 | protected function printData() |
||
18 | { |
||
19 | $escape = function($value) { |
||
20 | return preg_match("~[\"\n,;\t]~", $value) || $value === "" |
||
21 | ? '"' . str_replace('"', '""', $value) . '"' |
||
22 | : $value; |
||
23 | }; |
||
24 | |||
25 | $print = function(array $row) { |
||
26 | print implode(',', $row) . "\n"; |
||
27 | }; |
||
28 | |||
29 | $columns = $this->grid[Column::ID]->getComponents(); |
||
30 | |||
31 | $header = []; |
||
32 | $headerItems = $this->header ? $this->header : $columns; |
||
33 | foreach ($headerItems as $column) { |
||
34 | $header[] = $this->header |
||
35 | ? $escape($column) |
||
36 | : $escape($column->getLabel()); |
||
37 | } |
||
38 | |||
39 | $print($header); |
||
40 | |||
41 | $datasource = $this->grid->getData(FALSE, FALSE, FALSE); |
||
42 | $iterations = ceil($datasource->getCount() / $this->fetchLimit); |
||
|
|||
43 | for ($i = 0; $i < $iterations; $i++) { |
||
44 | $datasource->limit($i * $this->fetchLimit, $this->fetchLimit); |
||
45 | $data = $this->customData |
||
46 | ? call_user_func_array($this->customData, [$datasource]) |
||
47 | : $datasource->getData(); |
||
48 | |||
49 | foreach ($data as $items) { |
||
50 | $row = []; |
||
51 | |||
52 | $columns = $this->customData |
||
53 | ? $items |
||
54 | : $columns; |
||
55 | |||
56 | foreach ($columns as $column) { |
||
57 | $row[] = $this->customData |
||
58 | ? $escape($column) |
||
59 | : $escape($column->renderExport($items)); |
||
60 | } |
||
61 | |||
62 | $print($row); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | |||
79 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: