Failed Conditions
Push — refactorCachePSR2 ( fec08c...b4b0b3 )
by Michael
06:04 queued 02:59
created

CacheParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A makeDefaultCacheDecision() 0 8 2
A addDependencies() 0 16 2
1
<?php
2
3
namespace dokuwiki\Cache;
4
5
/**
6
 * Parser caching
7
 */
8
class CacheParser extends Cache
9
{
10
11
    public $file = '';       // source file for cache
12
    public $mode = '';       // input mode (represents the processing the input file will undergo)
13
    public $page = '';
14
15
    /**
16
     *
17
     * @param string $id page id
18
     * @param string $file source file for cache
19
     * @param string $mode input mode
20
     */
21
    public function __construct($id, $file, $mode)
22
    {
23
        if ($id) {
24
            $this->page = $id;
25
        }
26
        $this->file = $file;
27
        $this->mode = $mode;
28
29
        $this->_event = 'PARSER_CACHE_USE';
0 ignored issues
show
Deprecated Code introduced by
The property dokuwiki\Cache\Cache::$_event has been deprecated with message: since 2019-02-02 use the respective getters instead!

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
30
        parent::__construct($file . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.' . $mode);
31
    }
32
33
    /**
34
     * method contains cache use decision logic
35
     *
36
     * @return bool               see useCache()
37
     */
38
    public function makeDefaultCacheDecision()
39
    {
40
41
        if (!file_exists($this->file)) {
42
            return false;
43
        }                   // source exists?
44
        return parent::makeDefaultCacheDecision();
45
    }
46
47
    protected function addDependencies()
48
    {
49
50
        // parser cache file dependencies ...
51
        $files = array(
52
            $this->file,                              // ... source
53
            DOKU_INC . 'inc/parser/Parser.php',                // ... parser
54
            DOKU_INC . 'inc/parser/handler.php',               // ... handler
55
        );
56
        $files = array_merge($files, getConfigFiles('main'));    // ... wiki settings
57
58
        $this->depends['files'] = !empty($this->depends['files']) ?
59
            array_merge($files, $this->depends['files']) :
60
            $files;
61
        parent::addDependencies();
62
    }
63
64
}
65