Completed
Push — master ( 7a6bdd...324ce1 )
by Sébastien
09:34
created

Configuration   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 97.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 25
c 1
b 0
f 0
dl 0
loc 119
ccs 34
cts 35
cp 0.9714
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadataCache() 0 3 1
A __construct() 0 10 2
A getResultCache() 0 3 1
A setResultCache() 0 3 1
A setMetadataCache() 0 3 1
A getTypes() 0 7 2
A setDbConfig() 0 5 1
A getDbConfig() 0 17 4
A setTypes() 0 3 1
1
<?php
2
3
namespace Bdf\Prime;
4
5
use Bdf\Prime\Connection\ConnectionConfig;
6
use Bdf\Prime\Types\TypesRegistry;
7
use Bdf\Prime\Types\TypesRegistryInterface;
8
use Doctrine\DBAL\Configuration as BaseConfiguration;
9
use Psr\SimpleCache\CacheInterface;
0 ignored issues
show
introduced by
Unused use statement
Loading history...
10
11
/**
12
 * Configuration
13
 */
14
class Configuration extends BaseConfiguration
15
{
16
    /**
17
     * Set configuration
18
     * 
19
     * @param array $options
20
     */
21 188
    public function __construct(array $options = [])
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before function; 0 found
Loading history...
22
    {
23 188
        $this->_attributes = $options + [
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Operation must be bracketed
Loading history...
24 188
            'sqlLogger'         => isset($options['logger']) ? $options['logger'] : null,
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
25
            'resultCache'       => null,
26
            'metadataCache'     => null,
27
            'dbConfig'          => null,
28
        ];
29
        
30 188
        unset($this->_attributes['logger']);
31 188
    }
32
    
33
    /**
34
     * Cache de resultat des requetes
35
     * 
36
     * @param \Bdf\Prime\Cache\CacheInterface $cache
37
     */
38 1
    public function setResultCache($cache)
0 ignored issues
show
introduced by
Type hint "\Bdf\Prime\Cache\CacheInterface" missing for $cache
Loading history...
39
    {
40 1
        $this->_attributes['resultCache'] = $cache;
41 1
    }
42
    
43
    /**
44
     * @return \Bdf\Prime\Cache\CacheInterface
45
     */
46 110
    public function getResultCache()
47
    {
48 110
        return $this->_attributes['resultCache'];
49
    }
50
    
51
    /**
52
     * Cache de metadata
53
     * 
54
     * @param CacheInterface $cache
55
     */
56 1
    public function setMetadataCache($cache)
0 ignored issues
show
introduced by
Type hint "CacheInterface" missing for $cache
Loading history...
57
    {
58 1
        $this->_attributes['metadataCache'] = $cache;
59 1
    }
60
    
61
    /**
62
     * @return CacheInterface
63
     */
64 109
    public function getMetadataCache()
65
    {
66 109
        return $this->_attributes['metadataCache'];
67
    }
68
    
69
    /**
70
     * Set db config.
71
     * 
72
     * Contains profil info to connect database
0 ignored issues
show
introduced by
Doc comment long description must end with a full stop
Loading history...
73
     * 
74
     * @param callable|ConnectionConfig|array $config   Config object or config file
75
     *
76
     * @deprecated Since 1.1. Use ConnectionRegistry to declare your connections.
0 ignored issues
show
introduced by
The text '@deprecated Since 1.1. Use ConnectionRegistry to declare your connections.' does not match the standard format: @deprecated in deprecation-version and is removed from removal-version. extra-info.
Loading history...
introduced by
Each @deprecated tag must have a @see tag immediately following it.
Loading history...
77
     */
78 2
    public function setDbConfig($config)
79
    {
80 2
        @trigger_error(__METHOD__.' is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.', E_USER_DEPRECATED);
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged; found: @trigger_error(__METHOD__...
Loading history...
introduced by
The trigger_error message '__METHOD__ is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.' does not match the strict standard format: thing is deprecated in deprecation-version and is removed from removal-version. extra-info. See cr-link
Loading history...
81
82 2
        $this->_attributes['dbConfig'] = $config;
83 2
    }
84
    
85
    /**
86
     * Get the db config object
87
     * 
88
     * @return ConnectionConfig
89
     *
90
     * @deprecated Since 1.1. Use ConnectionRegistry to declare your connections.
0 ignored issues
show
introduced by
The text '@deprecated Since 1.1. Use ConnectionRegistry to declare your connections.' does not match the standard format: @deprecated in deprecation-version and is removed from removal-version. extra-info.
Loading history...
introduced by
Each @deprecated tag must have a @see tag immediately following it.
Loading history...
91
     */
92 7
    public function getDbConfig()
93
    {
94 7
        @trigger_error(__METHOD__.' is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.', E_USER_DEPRECATED);
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged; found: @trigger_error(__METHOD__...
Loading history...
introduced by
The trigger_error message '__METHOD__ is deprecated since 1.1 and will be removed in 1.2. Use ConnectionRegistry to declare your connections.' does not match the strict standard format: thing is deprecated in deprecation-version and is removed from removal-version. extra-info. See cr-link
Loading history...
95
96 7
        if ($this->_attributes['dbConfig'] instanceof ConnectionConfig) {
97 3
            return $this->_attributes['dbConfig'];
98
        }
99
100 6
        if (is_callable($this->_attributes['dbConfig'])) {
101
            $this->_attributes['dbConfig'] = $this->_attributes['dbConfig']($this);
102
        }
103
104 6
        if (! $this->_attributes['dbConfig'] instanceof ConnectionConfig) {
0 ignored issues
show
introduced by
A unary operator statement must not be followed by a space
Loading history...
105 6
            $this->_attributes['dbConfig'] = new ConnectionConfig((array) $this->_attributes['dbConfig']);
0 ignored issues
show
Deprecated Code introduced by
The class Bdf\Prime\Connection\ConnectionConfig has been deprecated: Since 1.1 ( Ignorable by Annotation )

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

105
            $this->_attributes['dbConfig'] = /** @scrutinizer ignore-deprecated */ new ConnectionConfig((array) $this->_attributes['dbConfig']);
Loading history...
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
106
        }
107
108 6
        return $this->_attributes['dbConfig'];
109
    }
110
111
    /**
112
     * Set common type registry
113
     *
114
     * @param TypesRegistryInterface $types
115
     */
116 128
    public function setTypes(TypesRegistryInterface $types)
117
    {
118 128
        $this->_attributes['types'] = $types;
119 128
    }
120
121
    /**
122
     * Get common types registry
123
     *
124
     * @return TypesRegistryInterface
125
     */
126 180
    public function getTypes()
127
    {
128 180
        if (!isset($this->_attributes['types'])) {
129 128
            $this->setTypes(new TypesRegistry());
130
        }
131
132 180
        return $this->_attributes['types'];
133
    }
134
}
135