SchemaConfig::getExcludes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/sprout/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/sprout
12
 */
13
14
namespace Graze\Sprout\Config;
15
16
use Graze\ConfigValidation\ConfigValidatorInterface;
17
use Graze\ConfigValidation\Validate;
18
use Respect\Validation\Validator as v;
19
20
class SchemaConfig implements SchemaConfigInterface
21
{
22
    const CONFIG_SCHEMA     = 'schema';
23
    const CONFIG_EXCLUDE    = 'exclude';
24
    const CONFIG_CONNECTION = 'connection';
25
    const CONFIG_DIR_NAME   = 'dirName';
26
27
    /** @var string */
28
    private $schema;
29
    /** @var string[] */
30
    private $exclude;
31
    /** @var ConnectionConfigInterface */
32
    private $connection;
33
    /** @var string */
34
    private $dirName;
35
36
    /**
37
     * SchemaConfig constructor.
38
     *
39
     * @param array $options Array of options
40
     *
41
     * @throws \Graze\ConfigValidation\Exceptions\ConfigValidationFailedException
42
     */
43
    public function __construct(array $options = [])
44
    {
45
        $options = static::getValidator()->validate($options);
46
        $this->schema = $options[static::CONFIG_SCHEMA];
47
        $this->exclude = $options[static::CONFIG_EXCLUDE];
48
        $this->connection = new ConnectionConfig($options[static::CONFIG_CONNECTION]);
49
        $this->dirName = $options[static::CONFIG_DIR_NAME] ?? $this->schema;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSchema(): string
56
    {
57
        return $this->schema;
58
    }
59
60
    /**
61
     * @return ConnectionConfigInterface
62
     */
63
    public function getConnection(): ConnectionConfigInterface
64
    {
65
        return $this->connection;
66
    }
67
68
    /**
69
     * @return ConfigValidatorInterface
70
     */
71
    public static function getValidator(): ConfigValidatorInterface
72
    {
73
        return Validate::arr(false)
74
                       ->addChild(static::CONFIG_CONNECTION, ConnectionConfig::getValidator())
75
                       ->optional(static::CONFIG_SCHEMA, v::stringType())
76
                       ->optional(static::CONFIG_EXCLUDE, v::arrayVal()->each(v::stringType()), [])
77
                       ->optional(static::CONFIG_DIR_NAME, v::stringType());
78
    }
79
80
    /**
81
     * @return string[]
82
     */
83
    public function getExcludes(): array
84
    {
85
        return $this->exclude;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getDirName(): string
92
    {
93
        return $this->dirName;
94
    }
95
}
96