Complex classes like Smarty_Template_Cached 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_Template_Cached, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class Smarty_Template_Cached extends Smarty_Template_Resource_Base |
||
18 | { |
||
19 | /** |
||
20 | * Cache Is Valid |
||
21 | * |
||
22 | * @var boolean |
||
23 | */ |
||
24 | public $valid = null; |
||
25 | |||
26 | /** |
||
27 | * CacheResource Handler |
||
28 | * |
||
29 | * @var Smarty_CacheResource |
||
30 | */ |
||
31 | public $handler = null; |
||
32 | |||
33 | /** |
||
34 | * Template Cache Id (Smarty_Internal_Template::$cache_id) |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public $cache_id = null; |
||
39 | |||
40 | /** |
||
41 | * saved cache lifetime in seconds |
||
42 | * |
||
43 | * @var integer |
||
44 | */ |
||
45 | public $cache_lifetime = 0; |
||
46 | |||
47 | /** |
||
48 | * Id for cache locking |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | public $lock_id = null; |
||
53 | |||
54 | /** |
||
55 | * flag that cache is locked by this instance |
||
56 | * |
||
57 | * @var bool |
||
58 | */ |
||
59 | public $is_locked = false; |
||
60 | |||
61 | /** |
||
62 | * Source Object |
||
63 | * |
||
64 | * @var Smarty_Template_Source |
||
65 | */ |
||
66 | public $source = null; |
||
67 | |||
68 | /** |
||
69 | * Nocache hash codes of processed compiled templates |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | public $hashes = array(); |
||
74 | |||
75 | /** |
||
76 | * Flag if this is a cache resource |
||
77 | * |
||
78 | * @var bool |
||
79 | */ |
||
80 | public $isCache = true; |
||
81 | |||
82 | /** |
||
83 | * create Cached Object container |
||
84 | * |
||
85 | * @param Smarty_Internal_Template $_template template object |
||
86 | * |
||
87 | * @throws \SmartyException |
||
88 | */ |
||
89 | public function __construct(Smarty_Internal_Template $_template) |
||
99 | |||
100 | /** |
||
101 | * @param Smarty_Internal_Template $_template |
||
102 | * |
||
103 | * @return Smarty_Template_Cached |
||
104 | */ |
||
105 | public static function load(Smarty_Internal_Template $_template) |
||
116 | |||
117 | /** |
||
118 | * Render cache template |
||
119 | * |
||
120 | * @param \Smarty_Internal_Template $_template |
||
121 | * @param bool $no_output_filter |
||
122 | * |
||
123 | * @throws \Exception |
||
124 | */ |
||
125 | public function render(Smarty_Internal_Template $_template, $no_output_filter = true) |
||
146 | |||
147 | /** |
||
148 | * Check if cache is valid, lock cache if required |
||
149 | * |
||
150 | * @param \Smarty_Internal_Template $_template |
||
151 | * |
||
152 | * @return bool flag true if cache is valid |
||
153 | */ |
||
154 | public function isCached(Smarty_Internal_Template $_template) |
||
224 | |||
225 | /** |
||
226 | * Process cached template |
||
227 | * |
||
228 | * @param Smarty_Internal_Template $_template template object |
||
229 | * @param bool $update flag if called because cache update |
||
230 | */ |
||
231 | public function process(Smarty_Internal_Template $_template, $update = false) |
||
242 | |||
243 | /** |
||
244 | * Read cache content from handler |
||
245 | * |
||
246 | * @param Smarty_Internal_Template $_template template object |
||
247 | * |
||
248 | * @return string|false content |
||
249 | */ |
||
250 | public function read(Smarty_Internal_Template $_template) |
||
257 | } |
||
258 |