Failed Conditions
Push — master ( 36acc3...2eb342 )
by Adrien
36:49
created

Settings::setLibXmlLoaderOptions()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 3
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
     * The cache implementation to be used for cell collection.
29
     *
30
     * @var CacheInterface
31
     */
32
    private static $cache;
33
34
    /**
35
     * Set the locale code to use for formula translations and any special formatting.
36
     *
37
     * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
38
     *
39
     * @return bool Success or failure
40
     */
41
    public static function setLocale($locale)
42
    {
43
        return Calculation::getInstance()->setLocale($locale);
44
    }
45
46
    /**
47
     * Identify to PhpSpreadsheet the external library to use for rendering charts.
48
     *
49
     * @param string $rendererClass Class name of the chart renderer
50
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
51
     *
52
     * @throws Exception
53
     */
54 1
    public static function setChartRenderer($rendererClass)
55
    {
56 1
        if (!is_a($rendererClass, IRenderer::class, true)) {
57
            throw new Exception('Chart renderer must implement ' . IRenderer::class);
58
        }
59
60 1
        self::$chartRenderer = $rendererClass;
61 1
    }
62
63
    /**
64
     * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use.
65
     *
66
     * @return null|string Class name of the chart renderer
67
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
68
     */
69 1
    public static function getChartRenderer()
70
    {
71 1
        return self::$chartRenderer;
72
    }
73
74
    /**
75
     * Set default options for libxml loader.
76
     *
77
     * @param int $options Default options for libxml loader
78
     */
79 18
    public static function setLibXmlLoaderOptions($options)
80
    {
81 18
        if ($options === null && defined('LIBXML_DTDLOAD')) {
0 ignored issues
show
introduced by
The condition $options === null is always false.
Loading history...
82 1
            $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
83
        }
84 18
        self::$libXmlLoaderOptions = $options;
85 18
    }
86
87
    /**
88
     * Get default options for libxml loader.
89
     * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
90
     *
91
     * @return int Default options for libxml loader
92
     */
93 57
    public static function getLibXmlLoaderOptions()
94
    {
95 57
        if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) {
0 ignored issues
show
introduced by
The condition self::libXmlLoaderOptions === null is always false. If self::libXmlLoaderOptions === null can have other possible types, add them to src/PhpSpreadsheet/Settings.php:23
Loading history...
96 16
            self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
97 55
        } elseif (self::$libXmlLoaderOptions === null) {
0 ignored issues
show
introduced by
The condition self::libXmlLoaderOptions === null is always false. If self::libXmlLoaderOptions === null can have other possible types, add them to src/PhpSpreadsheet/Settings.php:23
Loading history...
98
            self::$libXmlLoaderOptions = true;
99
        }
100
101 57
        return self::$libXmlLoaderOptions;
102
    }
103
104
    /**
105
     * Sets the implementation of cache that should be used for cell collection.
106
     *
107
     * @param CacheInterface $cache
108
     */
109
    public static function setCache(CacheInterface $cache)
110
    {
111
        self::$cache = $cache;
112
    }
113
114
    /**
115
     * Gets the implementation of cache that should be used for cell collection.
116
     *
117
     * @return CacheInterface
118
     */
119 199
    public static function getCache()
120
    {
121 199
        if (!self::$cache) {
122 98
            self::$cache = new Memory();
123
        }
124
125 199
        return self::$cache;
126
    }
127
}
128