Conditions | 13 |
Paths | 25 |
Total Lines | 44 |
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 |
||
32 | public static function generate(){ |
||
33 | global $conf; |
||
34 | if($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) return false; |
||
35 | |||
36 | $sitemap = Mapper::getFilePath(); |
||
37 | |||
38 | if(file_exists($sitemap)){ |
||
39 | if(!is_writable($sitemap)) return false; |
||
40 | }else{ |
||
41 | if(!is_writable(dirname($sitemap))) return false; |
||
42 | } |
||
43 | |||
44 | if(@filesize($sitemap) && |
||
45 | @filemtime($sitemap) > (time()-($conf['sitemap']*86400))){ // 60*60*24=86400 |
||
46 | dbglog('Sitemapper::generate(): Sitemap up to date'); |
||
|
|||
47 | return false; |
||
48 | } |
||
49 | |||
50 | dbglog("Sitemapper::generate(): using $sitemap"); |
||
51 | |||
52 | $pages = idx_get_indexer()->getPages(); |
||
53 | dbglog('Sitemapper::generate(): creating sitemap using '.count($pages).' pages'); |
||
54 | $items = array(); |
||
55 | |||
56 | // build the sitemap items |
||
57 | foreach($pages as $id){ |
||
58 | //skip hidden, non existing and restricted files |
||
59 | if(isHiddenPage($id)) continue; |
||
60 | if(auth_aclcheck($id,'',array()) < AUTH_READ) continue; |
||
61 | $item = Item::createFromID($id); |
||
62 | if ($item !== null) |
||
63 | $items[] = $item; |
||
64 | } |
||
65 | |||
66 | $eventData = array('items' => &$items, 'sitemap' => &$sitemap); |
||
67 | $event = new \dokuwiki\Extension\Event('SITEMAP_GENERATE', $eventData); |
||
68 | if ($event->advise_before(true)) { |
||
69 | //save the new sitemap |
||
70 | $event->result = io_saveFile($sitemap, Mapper::getXML($items)); |
||
71 | } |
||
72 | $event->advise_after(); |
||
73 | |||
74 | return $event->result; |
||
75 | } |
||
76 | |||
165 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.