Completed
Branch feature/split-orm (60a911)
by Anton
03:15
created

MongoConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 56
loc 56
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultDatabase() 4 4 1
A hasDatabase() 4 4 1
A databaseOptions() 4 4 1
A databaseNames() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ODM\Configs;
8
9
use Spiral\Core\InjectableConfig;
10
use Spiral\Core\Traits\Config\AliasTrait;
11
12 View Code Duplication
class MongoConfig extends InjectableConfig
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    use AliasTrait;
15
16
    /**
17
     * Configuration section.
18
     */
19
    const CONFIG = 'mongo';
20
21
    /**
22
     * @var array
23
     */
24
    protected $config = [
25
        'default'   => '',
26
        'aliases'   => [],
27
        'databases' => []
28
    ];
29
30
    /**
31
     * @return string
32
     */
33
    public function defaultDatabase(): string
34
    {
35
        return $this->config['default'];
36
    }
37
38
    /**
39
     * @param string $database
40
     *
41
     * @return bool
42
     */
43
    public function hasDatabase(string $database): bool
44
    {
45
        return isset($this->config['databases'][$database]);
46
    }
47
48
    /**
49
     * Database connection configuration.
50
     *
51
     * @param string $database
52
     *
53
     * @return array
54
     */
55
    public function databaseOptions(string $database): array
56
    {
57
        return $this->config['databases'][$database];
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function databaseNames(): array
64
    {
65
        return array_keys($this->config['databases']);
66
    }
67
}