Conditions | 3 |
Paths | 4 |
Total Lines | 74 |
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 |
||
95 | public function process() |
||
96 | { |
||
97 | if ($this->_isXhtml === null) { |
||
98 | $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML')); |
||
99 | } |
||
100 | |||
101 | $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']); |
||
102 | $this->_placeholders = array(); |
||
103 | |||
104 | // replace SCRIPTs (and minify) with placeholders |
||
105 | $this->_html = preg_replace_callback( |
||
106 | '/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i' |
||
107 | ,array($this, '_removeScriptCB') |
||
108 | ,$this->_html); |
||
109 | |||
110 | // replace STYLEs (and minify) with placeholders |
||
111 | $this->_html = preg_replace_callback( |
||
112 | '/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i' |
||
113 | ,array($this, '_removeStyleCB') |
||
114 | ,$this->_html); |
||
115 | |||
116 | // remove HTML comments (not containing IE conditional comments). |
||
117 | if ($this->_keepComments == false) { |
||
118 | $this->_html = preg_replace_callback( |
||
119 | '/<!--([\\s\\S]*?)-->/' |
||
120 | ,array($this, '_commentCB') |
||
121 | ,$this->_html); |
||
122 | } |
||
123 | |||
124 | // replace PREs with placeholders |
||
125 | $this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i' |
||
126 | ,array($this, '_removePreCB') |
||
127 | ,$this->_html); |
||
128 | |||
129 | // replace TEXTAREAs with placeholders |
||
130 | $this->_html = preg_replace_callback( |
||
131 | '/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i' |
||
132 | ,array($this, '_removeTextareaCB') |
||
133 | ,$this->_html); |
||
134 | |||
135 | // replace data: URIs with placeholders |
||
136 | $this->_html = preg_replace_callback( |
||
137 | '/(=("|\')data:.*\\2)/Ui' |
||
138 | ,array($this, '_removeDataURICB') |
||
139 | ,$this->_html); |
||
140 | |||
141 | // trim each line. |
||
142 | // replace by space instead of '' to avoid newline after opening tag getting zapped |
||
143 | $this->_html = preg_replace('/^\s+|\s+$/m', ' ', $this->_html); |
||
144 | |||
145 | // remove ws around block/undisplayed elements |
||
146 | $this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body' |
||
147 | .'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form' |
||
148 | .'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav' |
||
149 | .'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)' |
||
150 | .'|ul|video)\\b[^>]*>)/i', '$1', $this->_html); |
||
151 | |||
152 | // remove ws outside of all elements |
||
153 | $this->_html = preg_replace_callback( |
||
154 | '/>([^<]+)</' |
||
155 | ,array($this, '_outsideTagCB') |
||
156 | ,$this->_html); |
||
157 | |||
158 | // use newlines before 1st attribute in open tags (to limit line lengths) |
||
159 | //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html); |
||
160 | |||
161 | // fill placeholders |
||
162 | $this->_html = str_replace( |
||
163 | array_keys($this->_placeholders) |
||
164 | ,array_values($this->_placeholders) |
||
165 | ,$this->_html |
||
166 | ); |
||
167 | return $this->_html; |
||
168 | } |
||
169 | |||
274 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.