Failed Conditions
Push — master ( 1e7115...0e6238 )
by Mark
25:51
created

Settings   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Test Coverage

Coverage 68.75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 158
ccs 22
cts 32
cp 0.6875
rs 10
c 2
b 0
f 0
wmc 16

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setCache() 0 3 1
A setChartRenderer() 0 7 2
A setLibXmlLoaderOptions() 0 6 3
A getCache() 0 7 2
A setLibXmlDisableEntityLoader() 0 3 1
A getLibXmlLoaderOptions() 0 9 4
A getChartRenderer() 0 3 1
A getLibXmlDisableEntityLoader() 0 3 1
A setLocale() 0 3 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6
use PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer;
7
use PhpOffice\PhpSpreadsheet\Collection\Memory;
8
use Psr\SimpleCache\CacheInterface;
9
10
class Settings
11
{
12
    /**
13
     * Class name of the chart renderer used for rendering charts
14
     * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph.
15
     *
16
     * @var string
17
     */
18
    private static $chartRenderer;
19
20
    /**
21
     * Default options for libxml loader.
22
     *
23
     * @var int
24
     */
25
    private static $libXmlLoaderOptions = null;
26
27
    /**
28
     * Allow/disallow libxml_disable_entity_loader() call when not thread safe.
29
     * Default behaviour is to do the check, but if you're running PHP versions
30
     *      7.2 < 7.2.1
31
     *      7.1 < 7.1.13
32
     *      7.0 < 7.0.27
33
     *      5.6 ANY
34
     * then you may need to disable this check to prevent unwanted behaviour in other threads
35
     * SECURITY WARNING: Changing this flag is not recommended.
36
     *
37
     * @var bool
38
     */
39
    private static $libXmlDisableEntityLoader = true;
40
41
    /**
42
     * The cache implementation to be used for cell collection.
43
     *
44
     * @var CacheInterface
45
     */
46
    private static $cache;
47
48
    /**
49
     * Set the locale code to use for formula translations and any special formatting.
50
     *
51
     * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
52
     *
53
     * @return bool Success or failure
54
     */
55
    public static function setLocale($locale)
56
    {
57
        return Calculation::getInstance()->setLocale($locale);
58
    }
59
60
    /**
61
     * Identify to PhpSpreadsheet the external library to use for rendering charts.
62
     *
63
     * @param string $rendererClass Class name of the chart renderer
64
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
65
     *
66
     * @throws Exception
67
     */
68 1
    public static function setChartRenderer($rendererClass)
69
    {
70 1
        if (!is_a($rendererClass, IRenderer::class, true)) {
71
            throw new Exception('Chart renderer must implement ' . IRenderer::class);
72
        }
73
74 1
        self::$chartRenderer = $rendererClass;
75 1
    }
76
77
    /**
78
     * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use.
79
     *
80
     * @return null|string Class name of the chart renderer
81
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
82
     */
83 1
    public static function getChartRenderer()
84
    {
85 1
        return self::$chartRenderer;
86
    }
87
88
    /**
89
     * Set default options for libxml loader.
90
     *
91
     * @param int $options Default options for libxml loader
92
     */
93 19
    public static function setLibXmlLoaderOptions($options)
94
    {
95 19
        if ($options === null && defined('LIBXML_DTDLOAD')) {
0 ignored issues
show
introduced by
The condition $options === null is always false.
Loading history...
96 1
            $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
97
        }
98 19
        self::$libXmlLoaderOptions = $options;
99 19
    }
100
101
    /**
102
     * Get default options for libxml loader.
103
     * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
104
     *
105
     * @return int Default options for libxml loader
106
     */
107 72
    public static function getLibXmlLoaderOptions()
108
    {
109 72
        if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) {
0 ignored issues
show
introduced by
The condition self::libXmlLoaderOptions === null is always false.
Loading history...
110 17
            self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
111 70
        } elseif (self::$libXmlLoaderOptions === null) {
0 ignored issues
show
introduced by
The condition self::libXmlLoaderOptions === null is always false.
Loading history...
112
            self::$libXmlLoaderOptions = true;
113
        }
114
115 72
        return self::$libXmlLoaderOptions;
116
    }
117
118
    /**
119
     * Enable/Disable the entity loader for libxml loader.
120
     * Allow/disallow libxml_disable_entity_loader() call when not thread safe.
121
     * Default behaviour is to do the check, but if you're running PHP versions
122
     *      7.2 < 7.2.1
123
     *      7.1 < 7.1.13
124
     *      7.0 < 7.0.27
125
     *      5.6 ANY
126
     * then you may need to disable this check to prevent unwanted behaviour in other threads
127
     * SECURITY WARNING: Changing this flag to false is not recommended.
128
     *
129
     * @param bool $state
130
     */
131
    public static function setLibXmlDisableEntityLoader($state)
132
    {
133
        self::$libXmlDisableEntityLoader = (bool) $state;
134
    }
135
136
    /**
137
     * Return the state of the entity loader (disabled/enabled) for libxml loader.
138
     *
139
     * @return bool $state
140
     */
141 128
    public static function getLibXmlDisableEntityLoader()
142
    {
143 128
        return self::$libXmlDisableEntityLoader;
144
    }
145
146
    /**
147
     * Sets the implementation of cache that should be used for cell collection.
148
     *
149
     * @param CacheInterface $cache
150
     */
151
    public static function setCache(CacheInterface $cache)
152
    {
153
        self::$cache = $cache;
154
    }
155
156
    /**
157
     * Gets the implementation of cache that should be used for cell collection.
158
     *
159
     * @return CacheInterface
160
     */
161 237
    public static function getCache()
162
    {
163 237
        if (!self::$cache) {
164 100
            self::$cache = new Memory();
165
        }
166
167 237
        return self::$cache;
168
    }
169
}
170