Completed
Push — master ( 9bd298...a8c6bd )
by grégoire
01:57
created

DatabaseInspector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Pomm package.
4
 *
5
 * (c) 2014 - 2017 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Inspector;
11
12
use PommProject\Foundation\Client\Client;
13
14
/**
15
 * DatabaseInspector
16
 *
17
 * Global inspector, it will give informations about the following:
18
 *
19
 * * configuration settings
20
 * * version
21
 *
22
 * @package     Pomm
23
 * @copyright   2017 Grégoire HUBERT
24
 * @author      Grégoire HUBERT
25
 * @license     X11 {@link http://opensource.org/licenses/mit-license.php}
26
 *
27
 * @see Client
28
 */
29
class DatabaseInspector extends Client
30
{
31
32
    use InspectorTrait;
33
34
    /**
35
     * getClientType
36
     *
37
     * @see ClientInterface
38
     */
39
    public function getClientType()
40
    {
41
        return 'inspector';
42
    }
43
44
    /**
45
     * getClientIdentifier
46
     *
47
     * @see ClientInterface
48
     */
49
    public function getClientIdentifier()
50
    {
51
        return 'database';
52
    }
53
54
    /**
55
     * getVersion
56
     *
57
     * Return server version.
58
     *
59
     * @return  string
60
     */
61
    public function getVersion()
62
    {
63
        $row = $this
64
            ->executeSql("show server_version")
65
            ->current()
66
            ;
67
68
        return $row['server_version'];
69
    }
70
71
    /**
72
     * getSizePretty
73
     *
74
     * Return the human readable size of the inspected database.
75
     *
76
     * @return  string
77
     */
78
    public function getSizePretty()
79
    {
80
        $row = $this
81
            ->executeSql("select pg_size_pretty(pg_database_size(current_database())) as size")
82
            ->current()
83
            ;
84
85
        return $row['size'];
86
    }
87
88
    /**
89
     * getSize
90
     *
91
     * Return the database size in bytes
92
     *
93
     * @return  int
94
     */
95
    public function getSize()
96
    {
97
        $row = $this
98
            ->executeSql("select pg_database_size(current_database()) as size")
99
            ->current()
100
            ;
101
102
        return $row['size'];
103
    }
104
105
    /**
106
     * getName
107
     *
108
     * Return the database name
109
     *
110
     * @return  string
111
     */
112
    public function getName()
113
    {
114
        $row = $this
115
            ->executeSql("select current_database() as database_name")
116
            ->current()
117
            ;
118
119
        return $row['database_name'];
120
    }
121
}
122