Conditions | 14 |
Paths | 100 |
Total Lines | 71 |
Code Lines | 41 |
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 |
||
19 | public function cssStyleini($tpl, $preview=false) { |
||
20 | global $conf; |
||
21 | |||
22 | $stylesheets = array(); // mode, file => base |
||
23 | // guaranteed placeholder => value |
||
24 | $replacements = array( |
||
25 | '__text__' => "#000", |
||
26 | '__background__' => "#fff", |
||
27 | '__text_alt__' => "#999", |
||
28 | '__background_alt__' => "#eee", |
||
29 | '__text_neu__' => "#666", |
||
30 | '__background_neu__' => "#ddd", |
||
31 | '__border__' => "#ccc", |
||
32 | '__highlight__' => "#ff9", |
||
33 | '__link__' => "#00f", |
||
34 | ); |
||
35 | |||
36 | // load template's style.ini |
||
37 | $incbase = tpl_incdir($tpl); |
||
38 | $webbase = tpl_basedir($tpl); |
||
39 | $ini = $incbase.'style.ini'; |
||
40 | if(file_exists($ini)){ |
||
41 | $data = parse_ini_file($ini, true); |
||
42 | |||
43 | // stylesheets |
||
44 | if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ |
||
45 | $stylesheets[$mode][$incbase.$file] = $webbase; |
||
46 | } |
||
47 | |||
48 | // replacements |
||
49 | if(is_array($data['replacements'])){ |
||
50 | $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'],$webbase)); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | // load configs's style.ini |
||
55 | $webbase = DOKU_BASE; |
||
56 | $ini = DOKU_CONF."tpl/$tpl/style.ini"; |
||
57 | $incbase = dirname($ini).'/'; |
||
58 | if(file_exists($ini)){ |
||
59 | $data = parse_ini_file($ini, true); |
||
60 | |||
61 | // stylesheets |
||
62 | if(isset($data['stylesheets']) && is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ |
||
63 | $stylesheets[$mode][$incbase.$file] = $webbase; |
||
64 | } |
||
65 | |||
66 | // replacements |
||
67 | if(isset($data['replacements']) && is_array($data['replacements'])){ |
||
68 | $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'],$webbase)); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | // allow replacement overwrites in preview mode |
||
73 | if($preview) { |
||
74 | $webbase = DOKU_BASE; |
||
75 | $ini = $conf['cachedir'].'/preview.ini'; |
||
76 | if(file_exists($ini)) { |
||
77 | $data = parse_ini_file($ini, true); |
||
78 | // replacements |
||
79 | if(is_array($data['replacements'])) { |
||
80 | $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'], $webbase)); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return array( |
||
86 | 'stylesheets' => $stylesheets, |
||
87 | 'replacements' => $replacements |
||
88 | ); |
||
89 | } |
||
90 | |||
108 |