ServerTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 122
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getServerInfo() 0 4 1
A support() 0 4 1
A getCollations() 0 4 1
A serverFacade() 0 3 1
A getProcesses() 0 5 1
A getStatus() 0 5 1
A createDatabase() 0 4 1
A dropDatabase() 0 4 1
A getVariables() 0 5 1
A getDatabases() 0 5 1
1
<?php
2
3
namespace Lagdo\DbAdmin\Db\Traits;
4
5
use Lagdo\DbAdmin\Db\Facades\ServerFacade;
6
7
/**
8
 * Facade to server functions
9
 */
10
trait ServerTrait
11
{
12
    use AbstractTrait;
13
14
    /**
15
     * Get the facade
16
     *
17
     * @return ServerFacade
18
     */
19
    protected function serverFacade(): ServerFacade
20
    {
21
        return $this->di()->g(ServerFacade::class);
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public function getServerInfo(): array
28
    {
29
        $this->connectToServer();
30
        return $this->serverFacade()->getServerInfo();
31
    }
32
33
    /**
34
     * Check if a feature is supported
35
     *
36
     * @param string $feature
37
     *
38
     * @return bool
39
     */
40
    public function support(string $feature)
41
    {
42
        $this->connectToServer();
43
        return $this->serverFacade()->support($feature);
44
    }
45
46
    /**
47
     * Get the collation list
48
     *
49
     * @return array
50
     */
51
    public function getCollations(): array
52
    {
53
        $this->connectToServer();
54
        return $this->serverFacade()->getCollations();
55
    }
56
57
    /**
58
     * Get the database list
59
     *
60
     * @param bool $schemaAccess
61
     *
62
     * @return array
63
     */
64
    public function getDatabases(bool $schemaAccess): array
65
    {
66
        $this->connectToServer();
67
        $this->breadcrumbs()->clear()->item($this->utils->trans->lang('Databases'));
68
        return $this->serverFacade()->getDatabases($schemaAccess);
69
    }
70
71
    /**
72
     * Get the processes
73
     *
74
     * @return array
75
     */
76
    public function getProcesses(): array
77
    {
78
        $this->connectToServer();
79
        $this->breadcrumbs()->clear()->item($this->utils->trans->lang('Process list'));
80
        return $this->serverFacade()->getProcesses();
81
    }
82
83
    /**
84
     * Get the variables
85
     *
86
     * @return array
87
     */
88
    public function getVariables(): array
89
    {
90
        $this->connectToServer();
91
        $this->breadcrumbs()->clear()->item($this->utils->trans->lang('Variables'));
92
        return $this->serverFacade()->getVariables();
93
    }
94
95
    /**
96
     * Get the server status
97
     *
98
     * @return array
99
     */
100
    public function getStatus(): array
101
    {
102
        $this->connectToServer();
103
        $this->breadcrumbs()->clear()->item($this->utils->trans->lang('Status'));
104
        return $this->serverFacade()->getStatus();
105
    }
106
107
    /**
108
     * Create a database
109
     *
110
     * @param string $database  The database name
111
     * @param string $collation The database collation
112
     *
113
     * @return bool
114
     */
115
    public function createDatabase(string $database, string $collation = ''): bool
116
    {
117
        $this->connectToServer();
118
        return $this->serverFacade()->createDatabase($database, $collation);
119
    }
120
121
    /**
122
     * Drop a database
123
     *
124
     * @param string $database  The database name
125
     *
126
     * @return bool
127
     */
128
    public function dropDatabase(string $database): bool
129
    {
130
        $this->connectToServer();
131
        return $this->serverFacade()->dropDatabase($database);
132
    }
133
}
134