Conditions | 35 |
Paths | 201 |
Total Lines | 103 |
Code Lines | 54 |
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 |
||
121 | public function includeInHTML($templateFile, $content) |
||
122 | { |
||
123 | if ($this->themedRequest()) { |
||
124 | |||
125 | //===================================================================== |
||
126 | // start copy-ish from parent class |
||
127 | |||
128 | $hasHead = (strpos($content, '</head>') !== false || strpos($content, '</head ') !== false) ? true : false; |
||
129 | $hasRequirements = ($this->css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags) ? true: false; |
||
130 | if ($hasHead && $hasRequirements) { |
||
131 | $requirements = ''; |
||
132 | $jsRequirements = ''; |
||
133 | $requirementsCSSFiles = array(); |
||
134 | $requirementsJSFiles = array(); |
||
135 | |||
136 | // Combine files - updates $this->javascript and $this->css |
||
137 | $this->process_combined_files(); |
||
138 | $isDev = Director::isDev(); |
||
139 | foreach (array_diff_key($this->javascript, $this->blocked) as $file => $dummy) { |
||
140 | $ignore = in_array($file, self::$files_to_ignore) ? true : false; |
||
141 | if($isDev || $ignore) { |
||
142 | $path = Convert::raw2xml($this->path_for_file($file)); |
||
143 | if ($path) { |
||
144 | if ($isDev) { |
||
145 | $requirementsJSFiles[$path] = $path; |
||
146 | } |
||
147 | if(in_array($file, self::$files_to_ignore)) { |
||
148 | $jsRequirements .= "<script type=\"text/javascript\" src=\"$path\"></script>\n"; |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | |||
154 | // Add all inline JavaScript *after* including external files they might rely on |
||
155 | if ($this->customScript) { |
||
156 | foreach (array_diff_key($this->customScript, $this->blocked) as $script) { |
||
157 | $jsRequirements .= "<script type=\"text/javascript\">\n//<![CDATA[\n"; |
||
158 | $jsRequirements .= "$script\n"; |
||
159 | $jsRequirements .= "\n//]]>\n</script>\n"; |
||
160 | } |
||
161 | } |
||
162 | |||
163 | foreach (array_diff_key($this->css, $this->blocked) as $file => $params) { |
||
164 | $ignore = in_array($file, self::$files_to_ignore) ? true : false; |
||
165 | if($isDev || $ignore) { |
||
166 | $path = Convert::raw2xml($this->path_for_file($file)); |
||
167 | if ($path) { |
||
168 | $media = (isset($params['media']) && !empty($params['media'])) ? $params['media'] : ""; |
||
169 | if ($isDev) { |
||
170 | $requirementsCSSFiles[$path."_".$media] = $path; |
||
171 | } |
||
172 | if($ignore) { |
||
173 | if($media !== '') { |
||
174 | $media = " media=\"{$media}\""; |
||
175 | } |
||
176 | $requirements .= "<link rel=\"stylesheet\" type=\"text/css\"{$media} href=\"$path\" />\n"; |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | |||
182 | foreach (array_diff_key($this->customCSS, $this->blocked) as $css) { |
||
183 | $requirements .= "<style type=\"text/css\">\n$css\n</style>\n"; |
||
184 | } |
||
185 | |||
186 | foreach (array_diff_key($this->customHeadTags, $this->blocked) as $customHeadTag) { |
||
187 | $requirements .= "$customHeadTag\n"; |
||
188 | } |
||
189 | |||
190 | // Remove all newlines from code to preserve layout |
||
191 | $jsRequirements = preg_replace('/>\n*/', '>', $jsRequirements); |
||
192 | |||
193 | // Forcefully put the scripts at the bottom of the body instead of before the first |
||
194 | // script tag. |
||
195 | $content = preg_replace("/(<\/body[^>]*>)/i", $jsRequirements . "\\1", $content); |
||
196 | |||
197 | // Put CSS at the bottom of the head |
||
198 | $content = preg_replace("/(<\/head>)/i", $requirements . "\\1", $content); |
||
199 | |||
200 | //end copy-ish from parent class |
||
201 | //===================================================================== |
||
202 | |||
203 | //copy files ... |
||
204 | if ($this->canSaveRequirements()) { |
||
205 | |||
206 | //css |
||
207 | $cssFolder = '/themes/'.SSViewer::current_theme().'/'.self::$copy_css_to_folder; |
||
208 | |||
209 | foreach ($requirementsCSSFiles as $cssFile) { |
||
210 | $this->moveFileToRequirementsFolder($cssFile, $cssFolder); |
||
211 | } |
||
212 | //js |
||
213 | $jsFolder = '/themes/'.SSViewer::current_theme().'/'.self::$copy_js_to_folder; |
||
214 | foreach ($requirementsJSFiles as $jsFile) { |
||
215 | $this->moveFileToRequirementsFolder($jsFile, $jsFolder); |
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | return $content; |
||
220 | } else { |
||
221 | return parent::includeInHTML($templateFile, $content); |
||
222 | } |
||
223 | } |
||
224 | |||
314 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.