Conditions | 12 |
Paths | 577 |
Total Lines | 57 |
Code Lines | 33 |
Lines | 9 |
Ratio | 15.79 % |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
37 | class PluginInclude extends Plugin |
||
38 | { |
||
39 | /** |
||
40 | * @param $file |
||
41 | * @param null $cache_time |
||
42 | * @param null $cache_id |
||
43 | * @param null $compile_id |
||
44 | * @param string $data |
||
45 | * @param null $assign |
||
46 | * @param array $rest |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function process($file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array()) |
||
51 | { |
||
52 | $include = null; |
||
53 | if ($file === '') { |
||
54 | return ''; |
||
55 | } |
||
56 | |||
57 | View Code Duplication | if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) { |
|
|
|||
58 | // resource:identifier given, extract them |
||
59 | $resource = $m[1]; |
||
60 | $identifier = $m[2]; |
||
61 | } else { |
||
62 | // get the current template's resource |
||
63 | $resource = $this->core->getTemplate()->getResourceName(); |
||
64 | $identifier = $file; |
||
65 | } |
||
66 | |||
67 | try { |
||
68 | $include = $this->core->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id); |
||
69 | } |
||
70 | catch (SecurityException $e) { |
||
71 | $this->core->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING); |
||
72 | } |
||
73 | catch (Exception $e) { |
||
74 | $this->core->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING); |
||
75 | } |
||
76 | |||
77 | if ($include === null) { |
||
78 | $this->core->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.', |
||
79 | E_USER_WARNING); |
||
80 | } elseif ($include === false) { |
||
81 | $this->core->triggerError('Include : Resource "' . $resource . '" does not support includes.', |
||
82 | E_USER_WARNING); |
||
83 | } |
||
84 | |||
85 | if (is_string($data)) { |
||
86 | $vars = $this->core->readVar($data); |
||
87 | } else { |
||
88 | $vars = $data; |
||
89 | } |
||
90 | |||
91 | if (count($rest)) { |
||
92 | $vars = $rest + $vars; |
||
93 | } |
||
94 | |||
110 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.