Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
66 | { |
||
67 | $css = str_replace("\r\n", "\n", $css); |
||
68 | |||
69 | // preserve empty comment after '>' |
||
70 | // http://www.webdevout.net/css-hacks#in_css-selectors |
||
71 | $css = preg_replace('@>/\\*\\s*\\*/@', '>/*keep*/', $css); |
||
72 | |||
73 | // preserve empty comment between property and value |
||
74 | // http://css-discuss.incutio.com/?page=BoxModelHack |
||
75 | $css = preg_replace('@/\\*\\s*\\*/\\s*:@', '/*keep*/:', $css); |
||
76 | $css = preg_replace('@:\\s*/\\*\\s*\\*/@', ':/*keep*/', $css); |
||
77 | |||
78 | // apply callback to all valid comments (and strip out surrounding ws |
||
79 | $css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@' |
||
80 | ,array($this, '_commentCB'), $css); |
||
81 | |||
82 | // remove ws around { } and last semicolon in declaration block |
||
83 | $css = preg_replace('/\\s*{\\s*/', '{', $css); |
||
84 | $css = preg_replace('/;?\\s*}\\s*/', '}', $css); |
||
85 | |||
86 | // remove ws surrounding semicolons |
||
87 | $css = preg_replace('/\\s*;\\s*/', ';', $css); |
||
88 | |||
89 | // remove ws around urls |
||
90 | $css = preg_replace('/ |
||
91 | url\\( # url( |
||
92 | \\s* |
||
93 | ([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis) |
||
94 | \\s* |
||
95 | \\) # ) |
||
96 | /x', 'url($1)', $css); |
||
97 | |||
98 | // remove ws between rules and colons |
||
99 | $css = preg_replace('/ |
||
100 | \\s* |
||
101 | ([{;]) # 1 = beginning of block or rule separator |
||
102 | \\s* |
||
103 | ([\\*_]?[\\w\\-]+) # 2 = property (and maybe IE filter) |
||
104 | \\s* |
||
105 | : |
||
106 | \\s* |
||
107 | (\\b|[#\'"-]) # 3 = first character of a value |
||
108 | /x', '$1$2:$3', $css); |
||
109 | |||
110 | // remove ws in selectors |
||
111 | $css = preg_replace_callback('/ |
||
112 | (?: # non-capture |
||
113 | \\s* |
||
114 | [^~>+,\\s]+ # selector part |
||
115 | \\s* |
||
116 | [,>+~] # combinators |
||
117 | )+ |
||
118 | \\s* |
||
119 | [^~>+,\\s]+ # selector part |
||
120 | { # open declaration block |
||
121 | /x' |
||
122 | ,array($this, '_selectorsCB'), $css); |
||
123 | |||
124 | // minimize hex colors |
||
125 | $css = preg_replace('/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i' |
||
126 | , '$1#$2$3$4$5', $css); |
||
127 | |||
128 | // remove spaces between font families |
||
129 | $css = preg_replace_callback('/font-family:([^;}]+)([;}])/' |
||
130 | ,array($this, '_fontFamilyCB'), $css); |
||
131 | |||
132 | $css = preg_replace('/@import\\s+url/', '@import url', $css); |
||
133 | |||
134 | // replace any ws involving newlines with a single newline |
||
135 | $css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css); |
||
136 | |||
137 | // separate common descendent selectors w/ newlines (to limit line lengths) |
||
138 | $css = preg_replace('/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/', "$1\n$2{", $css); |
||
139 | |||
140 | // Use newline after 1st numeric value (to limit line lengths). |
||
141 | $css = preg_replace('/ |
||
142 | ((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value |
||
143 | \\s+ |
||
144 | /x' |
||
145 | ,"$1\n", $css); |
||
146 | |||
147 | // prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/ |
||
148 | $css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css); |
||
149 | |||
150 | return trim($css); |
||
151 | } |
||
152 | |||
153 | /** |
||
247 |