Failed Conditions
Push — refactorCachePSR2 ( 0db577 )
by Michael
02:54
created

CacheInstructions   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveCache() 0 5 2
A storeCache() 0 8 2
1
<?php
2
3
namespace dokuwiki\Cache;
4
5
/**
6
 * Caching of parser instructions
7
 */
8
class CacheInstructions extends \dokuwiki\Cache\CacheParser
9
{
10
11
    /**
12
     * @param string $id page id
13
     * @param string $file source file for cache
14
     */
15
    public function __construct($id, $file)
16
    {
17
        parent::__construct($id, $file, 'i');
18
    }
19
20
    /**
21
     * retrieve the cached data
22
     *
23
     * @param   bool $clean true to clean line endings, false to leave line endings alone
24
     * @return  array          cache contents
25
     */
26
    public function retrieveCache($clean = true)
27
    {
28
        $contents = io_readFile($this->cache, false);
29
        return !empty($contents) ? unserialize($contents) : array();
30
    }
31
32
    /**
33
     * cache $instructions
34
     *
35
     * @param   array $instructions the instruction to be cached
36
     * @return  bool                  true on success, false otherwise
37
     */
38
    public function storeCache($instructions)
39
    {
40
        if ($this->_nocache) {
41
            return false;
42
        }
43
44
        return io_savefile($this->cache, serialize($instructions));
45
    }
46
}
47