Conditions | 11 |
Paths | 42 |
Total Lines | 45 |
Code Lines | 26 |
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 |
||
16 | public function startCharts($charts, $elementsID = null) |
||
17 | { |
||
18 | if ($charts instanceof Chart) { |
||
19 | $charts = [$charts]; |
||
20 | |||
21 | if ($elementsID) { |
||
22 | if (!is_string($elementsID)) { |
||
23 | throw new GoogleChartsException('A string is expected for HTML element ID.'); |
||
24 | } |
||
25 | |||
26 | $elementsID = [$elementsID]; |
||
27 | } |
||
28 | } elseif (is_array($charts) && !empty($charts)) { |
||
29 | $this->checkChartsTypes($charts); |
||
30 | |||
31 | if (null !== $elementsID) { |
||
32 | $this->checkElementsId($charts, $elementsID); |
||
|
|||
33 | } |
||
34 | } else { |
||
35 | throw new GoogleChartsException('An instance of Chart or an array of Chart is expected.'); |
||
36 | } |
||
37 | |||
38 | $packages = []; |
||
39 | $drawChartName = ''; |
||
40 | for ($i = 0; $i < count($charts); ++$i) { |
||
41 | if ($elementsID) { |
||
42 | $charts[$i]->setElementID($elementsID[$i]); |
||
43 | } |
||
44 | |||
45 | if (!in_array($charts[$i]->getPackage(), $packages)) { |
||
46 | $packages[] = $charts[$i]->getPackage(); |
||
47 | } |
||
48 | $drawChartName .= $charts[$i]->getElementID(); |
||
49 | } |
||
50 | |||
51 | $js = $this->loadLibraries($packages); |
||
52 | |||
53 | $js .= $this->startCallback('drawChart'.ucfirst(md5($drawChartName))); |
||
54 | |||
55 | foreach ($charts as $chart) { |
||
56 | $js .= $chart->startDraw(); |
||
57 | } |
||
58 | |||
59 | return $js; |
||
60 | } |
||
61 | |||
164 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.