Completed
Push — master ( f5adf6...a90a41 )
by Michal
02:09
created

AbstractDataManager::tablesCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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