Completed
Push — master ( aa6910...722d75 )
by Timo
16:42
created

getIsUseConfigurationFromClosestTemplateEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017- Timo Schmidt <[email protected]
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
/**
28
 * This class encapsulates the access to the extension configuration.
29
 *
30
 * @package ApacheSolrForTypo3\Solr\System\Configuration
31
 * @author Timo Hund <[email protected]>
32
 */
33
class ExtensionConfiguration
34
{
35
36
    /**
37
     * ExtensionConfiguration constructor.
38
     * @param array $configurationToUse
39
     */
40 63
    public function __construct($configurationToUse = [])
41
    {
42 63
        if (empty($configurationToUse)) {
43 63
            $this->configuration =  unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['solr']);
0 ignored issues
show
Bug introduced by
The property configuration does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
        } else {
45 1
            $this->configuration = $configurationToUse;
46
        }
47 63
    }
48
49
    /**
50
     * @return bool
51
     */
52 63
    public function getIsUseConfigurationFromClosestTemplateEnabled()
53
    {
54 63
        return (bool) $this->getConfigurationOrDefaultValue('useConfigurationFromClosestTemplate', false);
55
    }
56
57
    /**
58
     * @param string $key
59
     * @param mixed $defaultValue
60
     * @return mixed
61
     */
62 63
    protected function getConfigurationOrDefaultValue($key, $defaultValue)
63
    {
64 63
        return isset($this->configuration[$key]) ? $this->configuration[$key] : $defaultValue;
65
    }
66
}
67