Completed
Push — master ( 47a956...6a7dae )
by Stéphane
02:49
created

Config::canCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Todaymade\Daux;
2
3
use Todaymade\Daux\Tree\Content;
4
use Todaymade\Daux\Format\HTML\Config as HTMLConfig;
5
6
class Config extends BaseConfig
7
{
8
    public function getTitle()
9
    {
10
        return $this['title'];
11
    }
12
13 9
    public function getCurrentPage()
14
    {
15 9
        return $this['current_page'];
16
    }
17
18 12
    public function setCurrentPage(Content $entry)
19
    {
20 12
        $this['current_page'] = $entry;
21 12
    }
22
23 43
    public function getDocumentationDirectory()
24
    {
25 43
        return $this['docs_directory'];
26
    }
27
28 43
    public function setDocumentationDirectory($documentationPath)
29
    {
30 43
        $this['docs_directory'] = $documentationPath;
31 43
    }
32
33
    public function getThemesDirectory()
34
    {
35
        return $this['themes_directory'];
36
    }
37
38
    public function setThemesDirectory($directory)
39
    {
40
        $this['themes_directory'] = $directory;
41
    }
42
43
    public function setThemesPath($themePath)
44
    {
45
        $this['themes_path'] = $themePath;
46
    }
47
48
    public function getThemesPath()
49
    {
50
        return $this['themes_path'];
51
    }
52
53
    public function setFormat($format)
54
    {
55
        $this['format'] = $format;
56
    }
57
58
    public function getFormat()
59
    {
60
        return $this['format'];
61
    }
62
63
    public function hasTimezone()
64
    {
65
        return isset($this['timezone']);
66
    }
67
68
    public function getTimezone()
69
    {
70
        return $this['timezone'];
71
    }
72
73
    public function isMultilanguage()
74
    {
75
        return array_key_exists('languages', $this) && !empty($this['languages']);
0 ignored issues
show
Bug introduced by Stéphane Goetz
$this of type Todaymade\Daux\Config is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
        return array_key_exists('languages', /** @scrutinizer ignore-type */ $this) && !empty($this['languages']);
Loading history...
76
    }
77
78
    public function isLive()
79
    {
80
        return $this['mode'] == Daux::LIVE_MODE;
81
    }
82
83 19
    public function isStatic()
84
    {
85 19
        return $this['mode'] == Daux::STATIC_MODE;
86
    }
87
88
    public function shouldInheritIndex()
89
    {
90
        // As the global configuration is always present, we
91
        // need to test for the existence of the legacy value
92
        // first. Then use the current value.
93
        if (array_key_exists('live', $this) && array_key_exists('inherit_index', $this['live'])) {
0 ignored issues
show
Bug introduced by Stéphane Goetz
$this of type Todaymade\Daux\Config is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
        if (array_key_exists('live', /** @scrutinizer ignore-type */ $this) && array_key_exists('inherit_index', $this['live'])) {
Loading history...
94
            return $this['live']['inherit_index'];
95
        }
96
97
        return $this['html']['inherit_index'];
98
    }
99
100
    public function setConfigurationOverrideFile($override_file)
101
    {
102
        $this['override_file'] = $override_file;
103
    }
104
105
    public function getConfigurationOverrideFile()
106
    {
107
        if (array_key_exists('override_file', $this)) {
0 ignored issues
show
Bug introduced by Stéphane Goetz
$this of type Todaymade\Daux\Config is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
        if (array_key_exists('override_file', /** @scrutinizer ignore-type */ $this)) {
Loading history...
108
            return $this['override_file'];
109
        }
110
111
        return null;
112
    }
113
114
    public function getConfluenceConfiguration()
115
    {
116
        return $this['confluence'];
117
    }
118
119 1
    public function getHTML()
120
    {
121 1
        return new HTMLConfig($this['html']);
122
    }
123
124
    public function canCache()
125
    {
126
        if (array_key_exists('cache', $this)) {
0 ignored issues
show
Bug introduced by Stéphane Goetz
$this of type Todaymade\Daux\Config is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

126
        if (array_key_exists('cache', /** @scrutinizer ignore-type */ $this)) {
Loading history...
127
            return $this['cache'];
128
        }
129
130
        return false;
131
    }
132
133
    public function getCacheKey()
134
    {
135
        $cloned = [];
136
        foreach ($this as $key => $value) {
137
            $cloned[$key] = ($value instanceof Entry) ? $value->dump() : $value;
0 ignored issues
show
Bug introduced by Stéphane Goetz
The type Todaymade\Daux\Entry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
138
        }
139
140
        return sha1(json_encode($cloned));
141
    }
142
}
143