Completed
Branch develop (c2aa4c)
by Anton
05:17
created

ODMConfig::databaseConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license MIT
6
 * @author  Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\ODM\Configs;
9
10
use Spiral\Core\InjectableConfig;
11
12
/**
13
 * Translation component configuration.
14
 */
15
class ODMConfig extends InjectableConfig
16
{
17
    /**
18
     * Configuration section.
19
     */
20
    const CONFIG = 'odm';
21
22
    /**
23
     * @var array
24
     */
25
    protected $config = [
26
        'default'   => '',
27
        'aliases'   => [],
28
        'databases' => [],
29
        'schemas'   => [
30
            'mutators'       => [],
31
            'mutatorAliases' => []
32
        ]
33
    ];
34
35
    /**
36
     * @return string
37
     */
38
    public function defaultDatabase()
39
    {
40
        return $this->config['default'];
41
    }
42
43
    /**
44
     * @param string $alias
45
     * @return string
46
     */
47 View Code Duplication
    public function resolveAlias($alias)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        while (isset($this->config['aliases'][$alias])) {
50
            //Resolving database alias
51
            $alias = $this->config['aliases'][$alias];
52
        }
53
54
        return $alias;
55
    }
56
57
    /**
58
     * @param string $database
59
     * @return bool
60
     */
61
    public function hasDatabase($database)
62
    {
63
        return isset($this->config['databases'][$database]);
64
    }
65
66
    /**
67
     * Database connection configuration.
68
     *
69
     * @param string $database
70
     * @return array
71
     */
72
    public function databaseConfig($database)
73
    {
74
        return $this->config['databases'][$database];
75
    }
76
77
    /**
78
     * Resolve mutator alias.
79
     *
80
     * @param string $mutator
81
     * @return string
82
     */
83 View Code Duplication
    public function mutatorAlias($mutator)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        if (!is_string($mutator) || !isset($this->config['mutatorAliases'][$mutator])) {
86
            return $mutator;
87
        }
88
89
        return $this->config['mutatorAliases'][$mutator];
90
    }
91
92
    /**
93
     * Get list of mutators associated with given type.
94
     *
95
     * @param string $type
96
     * @return array
97
     */
98
    public function getMutators($type)
99
    {
100
        return isset($this->config['mutators'][$type]) ? $this->config['mutators'][$type] : [];
101
    }
102
}