Completed
Pull Request — master (#37)
by Anton
06:21
created

ODMConfig::hasDatabase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
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
use Spiral\Core\Traits\Config\AliasTrait;
12
13
/**
14
 * Translation component configuration.
15
 */
16
class ODMConfig extends InjectableConfig
17
{
18
    use AliasTrait;
19
20
    /**
21
     * Configuration section.
22
     */
23
    const CONFIG = 'odm';
24
25
    /**
26
     * @var array
27
     */
28
    protected $config = [
29
        'default'   => '',
30
        'aliases'   => [],
31
        'databases' => [],
32
        'schemas'   => [
33
            'mutators'       => [],
34
            'mutatorAliases' => []
35
        ]
36
    ];
37
38
    /**
39
     * @return string
40
     */
41
    public function defaultDatabase()
42
    {
43
        return $this->config['default'];
44
    }
45
46
    /**
47
     * @param string $database
48
     * @return bool
49
     */
50
    public function hasDatabase($database)
51
    {
52
        return isset($this->config['databases'][$database]);
53
    }
54
55
    /**
56
     * Database connection configuration.
57
     *
58
     * @param string $database
59
     * @return array
60
     */
61
    public function databaseConfig($database)
62
    {
63
        return $this->config['databases'][$database];
64
    }
65
66
    /**
67
     * Resolve mutator alias.
68
     *
69
     * @param string $mutator
70
     * @return string
71
     */
72 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...
73
    {
74
        if (!is_string($mutator) || !isset($this->config['schemas']['mutatorAliases'][$mutator])) {
75
            return $mutator;
76
        }
77
78
        return $this->config['schemas']['mutatorAliases'][$mutator];
79
    }
80
81
    /**
82
     * Get list of mutators associated with given type.
83
     *
84
     * @param string $type
85
     * @return array
86
     */
87
    public function getMutators($type)
88
    {
89
        return isset($this->config['schemas']['mutators'][$type])
90
            ? $this->config['schemas']['mutators'][$type]
91
            : [];
92
    }
93
}