Conditions | 12 |
Paths | 11 |
Total Lines | 71 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 3 |
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 |
||
68 | public function generateResources($moduleList, $templatePath = 'default') |
||
69 | { |
||
70 | // Cache main web resources |
||
71 | foreach (array(array('js'), array('css', 'less'), array('coffee')) as $rts) { |
||
72 | // Get first resource type as extension |
||
73 | $rt = $rts[0]; |
||
74 | |||
75 | $hash_name = ''; |
||
76 | |||
77 | // Iterate gathered namespaces for their resources |
||
78 | /** @var Module $module */ |
||
79 | foreach ($moduleList as $id => $module) { |
||
80 | // If necessary resources has been collected |
||
81 | foreach ($rts as $_rt) { |
||
82 | if (isset($module->resourceMap->$_rt)) { |
||
83 | foreach ($module->resourceMap->$_rt as $resource) { |
||
84 | // Created string with last resource modification time |
||
85 | $hash_name .= filemtime($resource); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | // Get hash that's describes resource status |
||
92 | $hash_name = md5($hash_name) . '.' . $rt; |
||
93 | |||
94 | $file = $hash_name; |
||
95 | |||
96 | $dir = str_replace(array('/', '.'), '_', $templatePath); |
||
97 | |||
98 | // If cached file does not exists |
||
99 | if ($this->cache_refresh($file, true, $dir)) { |
||
|
|||
100 | // Read content of resource files |
||
101 | $content = ''; |
||
102 | foreach ($moduleList as $id => $module) { |
||
103 | $this->currentModule = $module; |
||
104 | // If this ns has resources of specified type |
||
105 | foreach ($rts as $_rt) { |
||
106 | if (isset($module->resourceMap->$_rt)) { |
||
107 | //TODO: If you will remove & from iterator - system will fail at last element |
||
108 | foreach ($module->resourceMap->$_rt as $resource) { |
||
109 | // Store current processing resource |
||
110 | $this->currentResource = $resource; |
||
111 | // Read resource file |
||
112 | $c = file_get_contents($resource); |
||
113 | // Rewrite url in css |
||
114 | if ($rt == 'css') { |
||
115 | $c = preg_replace_callback('/url\s*\(\s*(\'|\")?([^\)\s\'\"]+)(\'|\")?\s*\)/i', |
||
116 | array($this, 'src_replace_callback'), $c); |
||
117 | } |
||
118 | // Gather processed resource text together |
||
119 | $content .= "\n\r" . $c; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | // Fire event that new resource has been generated |
||
126 | Event::fire(self::EVENT_CREATED, array($rt, &$content, &$file, &$this)); |
||
127 | |||
128 | // Fix updated resource file with new path to it |
||
129 | $this->updated[$rt] = $file; |
||
130 | |||
131 | // Запишем содержание нового "собранного" ресурса |
||
132 | file_put_contents($file, $content); |
||
133 | } |
||
134 | |||
135 | // Save path to resource cache |
||
136 | $this->cached[$rt][$templatePath] = __SAMSON_CACHE_PATH . $this->id . '/' . $dir . '/' . $hash_name; |
||
137 | } |
||
138 | } |
||
139 | |||
218 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.