Complex classes like Smarty_Internal_Configfileparser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Smarty_Internal_Configfileparser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class Smarty_Internal_Configfileparser |
||
25 | { |
||
26 | // line 25 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
27 | const TPC_OPENB = 1; |
||
28 | const TPC_SECTION = 2; |
||
29 | const TPC_CLOSEB = 3; |
||
30 | const TPC_DOT = 4; |
||
31 | const TPC_ID = 5; |
||
32 | const TPC_EQUAL = 6; |
||
33 | const TPC_FLOAT = 7; |
||
34 | const TPC_INT = 8; |
||
35 | const TPC_BOOL = 9; |
||
36 | const TPC_SINGLE_QUOTED_STRING = 10; |
||
37 | const TPC_DOUBLE_QUOTED_STRING = 11; |
||
38 | const TPC_TRIPPLE_QUOTES = 12; |
||
39 | const TPC_TRIPPLE_TEXT = 13; |
||
40 | const TPC_TRIPPLE_QUOTES_END = 14; |
||
41 | const TPC_NAKED_STRING = 15; |
||
42 | const TPC_OTHER = 16; |
||
43 | const TPC_NEWLINE = 17; |
||
44 | const TPC_COMMENTSTART = 18; |
||
45 | const YY_NO_ACTION = 60; |
||
46 | const YY_ACCEPT_ACTION = 59; |
||
47 | const YY_ERROR_ACTION = 58; |
||
48 | const YY_SZ_ACTTAB = 38; |
||
49 | const YY_SHIFT_USE_DFLT = -8; |
||
50 | const YY_SHIFT_MAX = 19; |
||
51 | const YY_REDUCE_USE_DFLT = -17; |
||
52 | const YY_REDUCE_MAX = 10; |
||
53 | const YYNOCODE = 29; |
||
54 | const YYSTACKDEPTH = 100; |
||
55 | const YYNSTATE = 36; |
||
56 | const YYNRULE = 22; |
||
57 | const YYERRORSYMBOL = 19; |
||
58 | const YYERRSYMDT = 'yy0'; |
||
59 | const YYFALLBACK = 0; |
||
60 | |||
61 | public static $yy_action = array( |
||
62 | 32, 31, 30, 29, 35, 13, 19, 3, 24, 26, |
||
63 | 59, 9, 14, 1, 16, 25, 11, 28, 25, 11, |
||
64 | 17, 27, 34, 20, 18, 15, 23, 5, 6, 22, |
||
65 | 10, 8, 4, 12, 2, 33, 7, 21, |
||
66 | ); |
||
67 | |||
68 | public static $yy_lookahead = array( |
||
69 | 7, 8, 9, 10, 11, 12, 5, 23, 15, 16, |
||
70 | 20, 21, 2, 23, 4, 17, 18, 14, 17, 18, |
||
71 | 13, 14, 25, 26, 15, 2, 17, 3, 3, 17, |
||
72 | 25, 25, 6, 1, 23, 27, 22, 24, |
||
73 | ); |
||
74 | |||
75 | public static $yy_shift_ofst = array( |
||
76 | -8, 1, 1, 1, -7, -2, -2, 32, -8, -8, |
||
77 | -8, 9, 10, 7, 25, 24, 23, 3, 12, 26, |
||
78 | ); |
||
79 | |||
80 | public static $yy_reduce_ofst = array( |
||
81 | -10, -3, -3, -3, 8, 6, 5, 13, 11, 14, |
||
82 | -16, |
||
83 | ); |
||
84 | |||
85 | public static $yyExpectedTokens = array( |
||
86 | array(), |
||
87 | array(5, 17, 18,), |
||
88 | array(5, 17, 18,), |
||
89 | array(5, 17, 18,), |
||
90 | array(7, 8, 9, 10, 11, 12, 15, 16,), |
||
91 | array(17, 18,), |
||
92 | array(17, 18,), |
||
93 | array(1,), |
||
94 | array(), |
||
95 | array(), |
||
96 | array(), |
||
97 | array(15, 17,), |
||
98 | array(2, 4,), |
||
99 | array(13, 14,), |
||
100 | array(3,), |
||
101 | array(3,), |
||
102 | array(2,), |
||
103 | array(14,), |
||
104 | array(17,), |
||
105 | array(6,), |
||
106 | array(), |
||
107 | array(), |
||
108 | array(), |
||
109 | array(), |
||
110 | array(), |
||
111 | array(), |
||
112 | array(), |
||
113 | array(), |
||
114 | array(), |
||
115 | array(), |
||
116 | array(), |
||
117 | array(), |
||
118 | array(), |
||
119 | array(), |
||
120 | array(), |
||
121 | array(), |
||
122 | ); |
||
123 | |||
124 | public static $yy_default = array( |
||
125 | 44, 37, 41, 40, 58, 58, 58, 36, 44, 39, |
||
126 | 44, 58, 58, 58, 58, 58, 58, 58, 58, 58, |
||
127 | 43, 38, 57, 56, 53, 55, 54, 52, 51, 49, |
||
128 | 48, 47, 46, 45, 42, 50, |
||
129 | ); |
||
130 | |||
131 | public static $yyFallback = array(); |
||
132 | |||
133 | public static $yyRuleName = array( |
||
134 | 'start ::= global_vars sections', |
||
135 | 'global_vars ::= var_list', |
||
136 | 'sections ::= sections section', |
||
137 | 'sections ::=', |
||
138 | 'section ::= OPENB SECTION CLOSEB newline var_list', |
||
139 | 'section ::= OPENB DOT SECTION CLOSEB newline var_list', |
||
140 | 'var_list ::= var_list newline', |
||
141 | 'var_list ::= var_list var', |
||
142 | 'var_list ::=', |
||
143 | 'var ::= ID EQUAL value', |
||
144 | 'value ::= FLOAT', |
||
145 | 'value ::= INT', |
||
146 | 'value ::= BOOL', |
||
147 | 'value ::= SINGLE_QUOTED_STRING', |
||
148 | 'value ::= DOUBLE_QUOTED_STRING', |
||
149 | 'value ::= TRIPPLE_QUOTES TRIPPLE_TEXT TRIPPLE_QUOTES_END', |
||
150 | 'value ::= TRIPPLE_QUOTES TRIPPLE_QUOTES_END', |
||
151 | 'value ::= NAKED_STRING', |
||
152 | 'value ::= OTHER', |
||
153 | 'newline ::= NEWLINE', |
||
154 | 'newline ::= COMMENTSTART NEWLINE', |
||
155 | 'newline ::= COMMENTSTART NAKED_STRING NEWLINE', |
||
156 | ); |
||
157 | |||
158 | public static $yyRuleInfo = array( |
||
159 | array(0 => 20, 1 => 2), |
||
160 | array(0 => 21, 1 => 1), |
||
161 | array(0 => 22, 1 => 2), |
||
162 | array(0 => 22, 1 => 0), |
||
163 | array(0 => 24, 1 => 5), |
||
164 | array(0 => 24, 1 => 6), |
||
165 | array(0 => 23, 1 => 2), |
||
166 | array(0 => 23, 1 => 2), |
||
167 | array(0 => 23, 1 => 0), |
||
168 | array(0 => 26, 1 => 3), |
||
169 | array(0 => 27, 1 => 1), |
||
170 | array(0 => 27, 1 => 1), |
||
171 | array(0 => 27, 1 => 1), |
||
172 | array(0 => 27, 1 => 1), |
||
173 | array(0 => 27, 1 => 1), |
||
174 | array(0 => 27, 1 => 3), |
||
175 | array(0 => 27, 1 => 2), |
||
176 | array(0 => 27, 1 => 1), |
||
177 | array(0 => 27, 1 => 1), |
||
178 | array(0 => 25, 1 => 1), |
||
179 | array(0 => 25, 1 => 2), |
||
180 | array(0 => 25, 1 => 3), |
||
181 | ); |
||
182 | |||
183 | public static $yyReduceMap = array( |
||
184 | 0 => 0, |
||
185 | 2 => 0, |
||
186 | 3 => 0, |
||
187 | 19 => 0, |
||
188 | 20 => 0, |
||
189 | 21 => 0, |
||
190 | 1 => 1, |
||
191 | 4 => 4, |
||
192 | 5 => 5, |
||
193 | 6 => 6, |
||
194 | 7 => 7, |
||
195 | 8 => 8, |
||
196 | 9 => 9, |
||
197 | 10 => 10, |
||
198 | 11 => 11, |
||
199 | 12 => 12, |
||
200 | 13 => 13, |
||
201 | 14 => 14, |
||
202 | 15 => 15, |
||
203 | 16 => 16, |
||
204 | 17 => 17, |
||
205 | 18 => 17, |
||
206 | ); |
||
207 | |||
208 | /** |
||
209 | * helper map |
||
210 | * |
||
211 | * @var array |
||
212 | */ |
||
213 | private static $escapes_single = array( |
||
214 | '\\' => '\\', |
||
215 | '\'' => '\'' |
||
216 | ); |
||
217 | |||
218 | /** |
||
219 | * result status |
||
220 | * |
||
221 | * @var bool |
||
222 | */ |
||
223 | public $successful = true; |
||
224 | |||
225 | /** |
||
226 | * return value |
||
227 | * |
||
228 | * @var mixed |
||
229 | */ |
||
230 | public $retvalue = 0; |
||
231 | |||
232 | /** |
||
233 | * @var |
||
234 | */ |
||
235 | public $yymajor; |
||
236 | |||
237 | /** |
||
238 | * compiler object |
||
239 | * |
||
240 | * @var Smarty_Internal_Config_File_Compiler |
||
241 | */ |
||
242 | public $compiler = null; |
||
243 | |||
244 | /** |
||
245 | * smarty object |
||
246 | * |
||
247 | * @var Smarty |
||
248 | */ |
||
249 | public $smarty = null; |
||
250 | |||
251 | public $yyTraceFILE; |
||
252 | |||
253 | public $yyTracePrompt; |
||
254 | |||
255 | public $yyidx; |
||
256 | |||
257 | public $yyerrcnt; |
||
258 | |||
259 | public $yystack = array(); |
||
260 | |||
261 | public $yyTokenName = array( |
||
262 | '$', 'OPENB', 'SECTION', 'CLOSEB', |
||
263 | 'DOT', 'ID', 'EQUAL', 'FLOAT', |
||
264 | 'INT', 'BOOL', 'SINGLE_QUOTED_STRING', 'DOUBLE_QUOTED_STRING', |
||
265 | 'TRIPPLE_QUOTES', 'TRIPPLE_TEXT', 'TRIPPLE_QUOTES_END', 'NAKED_STRING', |
||
266 | 'OTHER', 'NEWLINE', 'COMMENTSTART', 'error', |
||
267 | 'start', 'global_vars', 'sections', 'var_list', |
||
268 | 'section', 'newline', 'var', 'value', |
||
269 | ); |
||
270 | |||
271 | /** |
||
272 | * lexer object |
||
273 | * |
||
274 | * @var Smarty_Internal_Configfilelexer |
||
275 | */ |
||
276 | private $lex; |
||
277 | |||
278 | /** |
||
279 | * internal error flag |
||
280 | * |
||
281 | * @var bool |
||
282 | */ |
||
283 | private $internalError = false; |
||
284 | |||
285 | /** |
||
286 | * copy of config_overwrite property |
||
287 | * |
||
288 | * @var bool |
||
289 | */ |
||
290 | private $configOverwrite = false; |
||
291 | |||
292 | /** |
||
293 | * copy of config_read_hidden property |
||
294 | * |
||
295 | * @var bool |
||
296 | */ |
||
297 | private $configReadHidden = false; |
||
298 | |||
299 | private $_retvalue; |
||
300 | |||
301 | /** |
||
302 | * constructor |
||
303 | * |
||
304 | * @param Smarty_Internal_Configfilelexer $lex |
||
305 | * @param Smarty_Internal_Config_File_Compiler $compiler |
||
306 | */ |
||
307 | public function __construct(Smarty_Internal_Configfilelexer $lex, Smarty_Internal_Config_File_Compiler $compiler) |
||
315 | |||
316 | public static function yy_destructor($yymajor, $yypminor) |
||
323 | |||
324 | /** |
||
325 | * parse single quoted string |
||
326 | * remove outer quotes |
||
327 | * unescape inner quotes |
||
328 | * |
||
329 | * @param string $qstr |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | private static function parse_single_quoted_string($qstr) |
||
348 | /** |
||
349 | * parse double quoted string |
||
350 | * |
||
351 | * @param string $qstr |
||
352 | * |
||
353 | * @return string |
||
354 | */ |
||
355 | private static function parse_double_quoted_string($qstr) |
||
360 | /** |
||
361 | * parse triple quoted string |
||
362 | * |
||
363 | * @param string $qstr |
||
364 | * |
||
365 | * @return string |
||
366 | */ |
||
367 | private static function parse_tripple_double_quoted_string($qstr) |
||
381 | |||
382 | public function PrintTrace() |
||
387 | |||
388 | public function tokenName($tokenType) |
||
399 | |||
400 | public function yy_pop_parser_stack() |
||
418 | |||
419 | public function __destruct() |
||
428 | |||
429 | public function yy_get_expected_tokens($token) |
||
513 | |||
514 | public function yy_is_expected_token($token) |
||
602 | |||
603 | public function yy_find_shift_action($iLookAhead) |
||
635 | |||
636 | public function yy_find_reduce_action($stateno, $iLookAhead) |
||
657 | |||
658 | public function yy_shift($yyNewState, $yyMajor, $yypMinor) |
||
697 | |||
698 | public function yy_r0() |
||
702 | |||
703 | public function yy_r1() |
||
708 | |||
709 | public function yy_r4() |
||
714 | |||
715 | // line 245 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
716 | public function yy_r5() |
||
726 | |||
727 | // line 250 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
728 | public function yy_r6() |
||
732 | |||
733 | // line 264 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
734 | public function yy_r7() |
||
739 | |||
740 | // line 269 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
741 | public function yy_r8() |
||
745 | |||
746 | // line 277 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
747 | public function yy_r9() |
||
755 | |||
756 | // line 281 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
757 | public function yy_r10() |
||
761 | |||
762 | // line 285 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
763 | public function yy_r11() |
||
767 | |||
768 | // line 291 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
769 | public function yy_r12() |
||
773 | |||
774 | // line 296 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
775 | public function yy_r13() |
||
779 | |||
780 | // line 300 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
781 | public function yy_r14() |
||
785 | |||
786 | // line 304 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
787 | public function yy_r15() |
||
791 | |||
792 | // line 308 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
793 | public function yy_r16() |
||
797 | |||
798 | // line 312 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
799 | public function yy_r17() |
||
803 | |||
804 | // line 316 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
805 | public function yy_reduce($yyruleno) |
||
847 | |||
848 | // line 320 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
849 | public function yy_parse_failed() |
||
858 | |||
859 | // line 324 "../smarty/lexer/smarty_internal_configfileparser.y" |
||
860 | public function yy_syntax_error($yymajor, $TOKEN) |
||
867 | |||
868 | public function yy_accept() |
||
881 | |||
882 | public function doParse($yymajor, $yytokenvalue) |
||
979 | |||
980 | /** |
||
981 | * parse optional boolean keywords |
||
982 | * |
||
983 | * @param string $str |
||
984 | * |
||
985 | * @return bool |
||
986 | */ |
||
987 | private function parse_bool($str) |
||
997 | |||
998 | /** |
||
999 | * set a config variable in target array |
||
1000 | * |
||
1001 | * @param array $var |
||
1002 | * @param array $target_array |
||
1003 | */ |
||
1004 | private function set_var(array $var, array &$target_array) |
||
1015 | |||
1016 | /** |
||
1017 | * add config variable to global vars |
||
1018 | * |
||
1019 | * @param array $vars |
||
1020 | */ |
||
1021 | private function add_global_vars(array $vars) |
||
1030 | |||
1031 | /** |
||
1032 | * add config variable to section |
||
1033 | * |
||
1034 | * @param string $section_name |
||
1035 | * @param array $vars |
||
1036 | */ |
||
1037 | private function add_section_vars($section_name, array $vars) |
||
1046 | } |
||
1047 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.