Conditions | 2 |
Paths | 2 |
Total Lines | 72 |
Code Lines | 44 |
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 |
||
94 | public function process() |
||
95 | { |
||
96 | if ($this->_isXhtml === null) { |
||
97 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
||
98 | } |
||
99 | |||
100 | $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
||
101 | $this->_placeholders = array(); |
||
102 | |||
103 | // replace SCRIPTs (and minify) with placeholders |
||
104 | $this->_html = preg_replace_callback( |
||
105 | '/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i' |
||
106 | ,array($this, '_removeScriptCB') |
||
107 | ,$this->_html); |
||
108 | |||
109 | // replace STYLEs (and minify) with placeholders |
||
110 | $this->_html = preg_replace_callback( |
||
111 | '/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i' |
||
112 | ,array($this, '_removeStyleCB') |
||
113 | ,$this->_html); |
||
114 | |||
115 | // remove HTML comments (not containing IE conditional comments). |
||
116 | $this->_html = preg_replace_callback( |
||
117 | '/<!--([\\s\\S]*?)-->/' |
||
118 | ,array($this, '_commentCB') |
||
119 | ,$this->_html); |
||
120 | |||
121 | // replace PREs with placeholders |
||
122 | $this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i' |
||
123 | ,array($this, '_removePreCB') |
||
124 | ,$this->_html); |
||
125 | |||
126 | // replace TEXTAREAs with placeholders |
||
127 | $this->_html = preg_replace_callback( |
||
128 | '/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i' |
||
129 | ,array($this, '_removeTextareaCB') |
||
130 | ,$this->_html); |
||
131 | |||
132 | // trim each line. |
||
133 | // @todo take into account attribute values that span multiple lines. |
||
134 | $this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html); |
||
135 | |||
136 | // remove ws around block/undisplayed elements |
||
137 | $this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' |
||
138 | .'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' |
||
139 | .'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' |
||
140 | .'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)' |
||
141 | .'|ul)\\b[^>]*>)/i', '$1', $this->_html); |
||
142 | |||
143 | // remove ws outside of all elements |
||
144 | $this->_html = preg_replace( |
||
145 | '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</' |
||
146 | ,'>$1$2$3<' |
||
147 | ,$this->_html); |
||
148 | |||
149 | // use newlines before 1st attribute in open tags (to limit line lengths) |
||
150 | $this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html); |
||
151 | |||
152 | // fill placeholders |
||
153 | $this->_html = str_replace( |
||
154 | array_keys($this->_placeholders) |
||
155 | ,array_values($this->_placeholders) |
||
156 | ,$this->_html |
||
157 | ); |
||
158 | // issue 229: multi-pass to catch scripts that didn't get replaced in textareas |
||
159 | $this->_html = str_replace( |
||
160 | array_keys($this->_placeholders) |
||
161 | ,array_values($this->_placeholders) |
||
162 | ,$this->_html |
||
163 | ); |
||
164 | return $this->_html; |
||
165 | } |
||
166 | |||
259 | } |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.