Configuration::isObservationEnabled()   A
last analyzed

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
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
namespace Aoe\Imgix\TYPO3;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2018 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use Aoe\Imgix\Utils\ArrayUtils;
29
use Aoe\Imgix\Utils\TypeUtils;
30
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
31
32
class Configuration
33
{
34
    /**
35
     * @var array
36
     */
37
    protected static $imgixFluidOptionsTypeMap = [
38
        'fluidClass' => TypeUtils::TYPE_STRING,
39
        'updateOnResize' => TypeUtils::TYPE_BOOLEAN,
40
        'updateOnResizeDown' => TypeUtils::TYPE_BOOLEAN,
41
        'updateOnPinchZoom' => TypeUtils::TYPE_BOOLEAN,
42
        'highDPRAutoScaleQuality' => TypeUtils::TYPE_BOOLEAN,
43
        'autoInsertCSSBestPractices' => TypeUtils::TYPE_BOOLEAN,
44
        'fitImgTagToContainerWidth' => TypeUtils::TYPE_BOOLEAN,
45
        'fitImgTagToContainerHeight' => TypeUtils::TYPE_BOOLEAN,
46
        'pixelStep' => TypeUtils::TYPE_INTEGER,
47
        'ignoreDPR' => TypeUtils::TYPE_BOOLEAN,
48
        'debounce' => TypeUtils::TYPE_INTEGER,
49
        'lazyLoad' => TypeUtils::TYPE_BOOLEAN,
50
        'lazyLoadOffsetVertical' => TypeUtils::TYPE_INTEGER,
51
        'lazyLoadOffsetHorizontal' => TypeUtils::TYPE_INTEGER,
52
        'throttle' => TypeUtils::TYPE_INTEGER,
53
        'maxWidth' => TypeUtils::TYPE_INTEGER,
54
        'maxHeight' => TypeUtils::TYPE_INTEGER,
55
    ];
56
57
    /**
58
     * @var array
59
     */
60
    private $configuration = array();
61
62
    /**
63
     * @var array
64
     */
65
    private $settings;
66
67
    /**
68
     * @param ConfigurationManagerInterface $configurationManager
69
     */
70 16
    public function __construct(ConfigurationManagerInterface $configurationManager)
71
    {
72 16
        $this->settings = $configurationManager->getConfiguration(
73 16
            ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
74 16
            'imgix'
75
        );
76 16
        $this->configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['imgix']);
77 16
    }
78
79
    /**
80
     * @return bool
81
     */
82 2
    public function isApiKeyConfigured()
83
    {
84 2
        $apiKey = $this->getApiKey();
85 2
        return (empty($apiKey) === false);
86
    }
87
88
    /**
89
     * @return bool
90
     */
91 2
    public function isEnabled()
92
    {
93 2
        if (isset($this->settings['enabled']) && '' !== $this->settings['enabled']) {
94 1
            return (boolean)$this->settings['enabled'];
95
        }
96 1
        return (boolean)$this->configuration['enabled'];
97
    }
98
99
    /**
100
     * @return bool
101
     */
102 2
    public function isFluidEnabled()
103
    {
104 2
        if (isset($this->settings['enableFluid']) && '' !== $this->settings['enableFluid']) {
105 1
            return (boolean)$this->settings['enableFluid'];
106
        }
107 1
        return (boolean)$this->configuration['enableFluid'];
108
    }
109
110
    /**
111
     * @return bool
112
     */
113 2
    public function isObservationEnabled()
114
    {
115 2
        if (isset($this->settings['enableObservation']) && '' !== $this->settings['enableObservation']) {
116 1
            return (boolean)$this->settings['enableObservation'];
117
        }
118 1
        return (boolean)$this->configuration['enableObservation'];
119
    }
120
121
    /**
122
     * @return string
123
     */
124 4
    public function getApiKey()
125
    {
126 4
        if (isset($this->settings['apiKey']) && '' !== $this->settings['apiKey']) {
127 1
            return (string)$this->settings['apiKey'];
128
        }
129 3
        return (string)$this->configuration['apiKey'];
130
    }
131
132
    /**
133
     * @return string
134
     */
135 2
    public function getHost()
136
    {
137 2
        if (isset($this->settings['host']) && '' !== $this->settings['host']) {
138 1
            return (string)$this->settings['host'];
139
        }
140 1
        return (string)$this->configuration['host'];
141
    }
142
143
    /**
144
     * @return array
145
     */
146 2
    public function getImgixFluidOptions()
147
    {
148 2
        if (isset($this->configuration['imgix.']['fluid.'])) {
149 1
            $options = ArrayUtils::filterEmptyValues($this->configuration['imgix.']['fluid.']);
150 1
            $options = TypeUtils::castTypesByMap(self::$imgixFluidOptionsTypeMap, $options);
151 1
            return $options;
152
        }
153 1
        return [];
154
    }
155
156
    /**
157
     * @return array
158
     */
159 2
    public function getImgixDefaultUrlParameters()
160
    {
161 2
        if (isset($this->configuration['imgix.']['defaultUrlParameters'])) {
162 1
            parse_str($this->configuration['imgix.']['defaultUrlParameters'], $defaultUrlParameters);
163 1
            return $defaultUrlParameters;
164
        }
165 1
        return [];
166
    }
167
}
168