Issues (1426)

app/src/Service/DatabaseConfigurationManager.php (21 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace Db3v4l\Service;
4
5
class DatabaseConfigurationManager
0 ignored issues
show
Missing doc comment for class DatabaseConfigurationManager
Loading history...
6
{
7
    protected $instanceList = [];
8
9
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
10
     * @param string[][] $instanceList key: instance name, values: connection specification
11
     */
12
    public function __construct(array $instanceList)
13
    {
14
        $this->instanceList = $instanceList;
15
    }
16
17
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
18
     * @param string|string[] $includeFilter accepts 'glob' wildcards. Empty = include all
0 ignored issues
show
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
19
     * @param string|string[] $excludeFilter accepts 'glob' wildcards. Empty = exclude none. NB: exclude match wins over include match
0 ignored issues
show
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
20
     * @return string[]
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
21
     */
22
    public function listInstances($includeFilter = [], $excludeFilter = [])
23
    {
24
        if (!is_array($includeFilter)) {
25
            $includeFilter = [$includeFilter];
26
        }
27
        if (!is_array($excludeFilter)) {
28
            $excludeFilter = [$excludeFilter];
29
        }
30
31
        $names = [];
32
        foreach(array_keys($this->instanceList) as $name) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
33
34
            if (empty($includeFilter)) {
35
                $include = true;
36
            } else {
37
                $include = false;
38
                foreach($includeFilter as $filter) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
39
                    if (fnmatch($filter, $name)) {
40
                        $include = true;
41
                        break;
42
                    }
43
                }
44
            }
45
46
            if ($include && !empty($excludeFilter)) {
47
                foreach($excludeFilter as $filter) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
48
                    if (fnmatch($filter, $name)) {
49
                        $include = false;
50
                        break;
51
                    }
52
                }
53
            }
54
55
            if ($include) {
56
                $names[] = $name;
57
            }
58
        }
59
        return $names;
60
    }
61
62
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
63
     * @param string $instanceName
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
64
     * @return string[]
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
65
     * @throws \OutOfBoundsException
0 ignored issues
show
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
66
     */
67
    public function getInstanceConfiguration($instanceName)
68
    {
69
        if (isset($this->instanceList[$instanceName])) {
70
            return $this->instanceList[$instanceName];
71
        }
72
73
        throw new \OutOfBoundsException("Unknown database instance '$instanceName'");
74
    }
75
76
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
77
     * @param string[] $instanceNames
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
78
     * @return string[][]
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
79
     * @throws \OutOfBoundsException
0 ignored issues
show
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
80
     */
81
    public function getInstancesConfiguration(array $instanceNames)
82
    {
83
        $instancesDefinitions = [];
84
        foreach($instanceNames as $instanceName)
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...)\n {\n"
Loading history...
85
        {
86
            $instancesDefinitions[$instanceName] = $this->getInstanceConfiguration($instanceName);
87
        }
88
        return $instancesDefinitions;
89
    }
90
}
91