Conditions | 13 |
Paths | 25 |
Total Lines | 44 |
Code Lines | 28 |
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 |
||
30 | public static function generate(){ |
||
31 | global $conf; |
||
32 | if($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) return false; |
||
33 | |||
34 | $sitemap = Mapper::getFilePath(); |
||
35 | |||
36 | if(file_exists($sitemap)){ |
||
37 | if(!is_writable($sitemap)) return false; |
||
38 | }else{ |
||
39 | if(!is_writable(dirname($sitemap))) return false; |
||
40 | } |
||
41 | |||
42 | if(@filesize($sitemap) && |
||
43 | @filemtime($sitemap) > (time()-($conf['sitemap']*86400))){ // 60*60*24=86400 |
||
44 | dbglog('Sitemapper::generate(): Sitemap up to date'); |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | dbglog("Sitemapper::generate(): using $sitemap"); |
||
49 | |||
50 | $pages = idx_get_indexer()->getPages(); |
||
51 | dbglog('Sitemapper::generate(): creating sitemap using '.count($pages).' pages'); |
||
52 | $items = array(); |
||
53 | |||
54 | // build the sitemap items |
||
55 | foreach($pages as $id){ |
||
56 | //skip hidden, non existing and restricted files |
||
57 | if(isHiddenPage($id)) continue; |
||
58 | if(auth_aclcheck($id,'',array()) < AUTH_READ) continue; |
||
59 | $item = Item::createFromID($id); |
||
60 | if ($item !== null) |
||
61 | $items[] = $item; |
||
62 | } |
||
63 | |||
64 | $eventData = array('items' => &$items, 'sitemap' => &$sitemap); |
||
65 | $event = new \Doku_Event('SITEMAP_GENERATE', $eventData); |
||
66 | if ($event->advise_before(true)) { |
||
67 | //save the new sitemap |
||
68 | $event->result = io_saveFile($sitemap, Mapper::getXML($items)); |
||
69 | } |
||
70 | $event->advise_after(); |
||
71 | |||
72 | return $event->result; |
||
73 | } |
||
74 | |||
163 |