Completed
Push — master ( 3e38c4...3f7c7b )
by Michal
02:49
created

AbstractDataManager::databaseNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace UniMan\Core\DataManager;
4
5
abstract class AbstractDataManager implements DataManagerInterface
6
{
7
    /**
8
     * @var array list of messages in format flash message => type of flash message (info, success, warning, danger)
9
     */
10
    protected $messages = [];
11
12
    /**
13
     * @param array $sorting
14
     * @return array
15
     */
16
    public function databaseNames(array $sorting = [])
17
    {
18
        $databases = array_map(function ($database) {
19
            return $database[$this->getDatabaseNameColumn()];
20
        }, $this->databases($sorting));
21
        return $databases;
22
    }
23
24
    /**
25
     * @param string $identifier
26
     * @return string
27
     */
28
    public function databaseName($identifier)
29
    {
30
        $databases = $this->databaseNames();
31
        return isset($databases[$identifier]) ? $databases[$identifier] : $identifier;
32
    }
33
34
    /**
35
     * Implement this method if permission canDeleteItem is true
36
     * @param string $type
37
     * @param string $table
38
     * @param string $item
39
     * @return boolean|null
40
     * @see DataManagerInterface
41
     */
42
    public function deleteItem($type, $table, $item)
43
    {
44
        return null;
45
    }
46
47
    /**
48
     * Implement this method if permission canDeleteTable is true
49
     * @param string $type
50
     * @param string $table
51
     * @return boolean|null
52
     * @see DataManagerInterface
53
     */
54
    public function deleteTable($type, $table)
55
    {
56
        return null;
57
    }
58
59
    /**
60
     * Implement this method if permission canDeleteDatabase is true
61
     * @param string $database
62
     * @return boolean|null
63
     * @see DataManagerInterface
64
     */
65
    public function deleteDatabase($database)
66
    {
67
        return null;
68
    }
69
70
    /**
71
     * Implement this method if permission canExecuteCommands is true
72
     * @param string $commands
73
     * @return array|null
74
     * @see DataManagerInterface
75
     */
76
    public function execute($commands)
77
    {
78
        return null;
79
    }
80
81
    /**
82
     * @return array
83
     * @see DataManagerInterface
84
     */
85
    final public function getMessages()
86
    {
87
        return $this->messages;
88
    }
89
90
    /**
91
     * add message to list of messages
92
     * @param string $message
93
     * @param string $type
94
     */
95
    final protected function addMessage($message, $type = 'info')
96
    {
97
        $this->messages[$message] = $type;
98
    }
99
100
    /**
101
     * @return string Name of column where database name is stored
102
     */
103
    abstract protected function getDatabaseNameColumn();
104
}
105