Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
MydbCredentials
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
8 / 8
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getHost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUsername
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPasswd
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDbname
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPort
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSocket
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFlags
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This file is part of the sshilko/php-sql-mydb package.
4 *
5 * (c) Sergei Shilko <contact@sshilko.com>
6 *
7 * MIT License
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 * @license https://opensource.org/licenses/mit-license.php MIT
12 */
13
14declare(strict_types = 1);
15
16namespace sql;
17
18/**
19 * @author Sergei Shilko <contact@sshilko.com>
20 * @license https://opensource.org/licenses/mit-license.php MIT
21 * @see https://github.com/sshilko/php-sql-mydb
22 */
23class MydbCredentials implements MydbCredentialsInterface
24{
25
26    /**
27     * Database credentials - hostname
28     * Can be either a host name or an IP address. Passing the null value or the string "localhost" to this parameter,
29     * the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.
30     *
31     * @see https://www.php.net/manual/en/mysqli.real-connect.php
32     */
33    protected string $host;
34
35    /**
36     * Database credentials - username
37     *
38     * @see https://www.php.net/manual/en/mysqli.real-connect.php
39     */
40    protected string $username;
41
42    /**
43     * Database credentials - password
44     * If provided or null, the MySQL server will attempt to authenticate the user against those user records
45     * which have no password only. This allows one username to be used with different permissions
46     * (depending on if a password as provided or not).
47     *
48     * @see https://www.php.net/manual/en/mysqli.real-connect.php
49     */
50    protected string $passwd;
51
52    /**
53     * Database credentials - database name
54     * If provided will specify the default database to be used when performing queries.
55     *
56     * @see https://www.php.net/manual/en/mysqli.real-connect.php
57     */
58    protected string $dbname;
59
60    /**
61     * Database credentials - port
62     * Specifies the port number to attempt to connect to the MySQL server.
63     *
64     * @see https://www.php.net/manual/en/mysqli.real-connect.php
65     */
66    protected ?int $port;
67
68    /**
69     * Database credentials - socket
70     * Specifies the socket or named pipe that should be used.
71     *
72     * @see https://www.php.net/manual/en/mysqli.real-connect.php
73     */
74    protected ?string $socket;
75
76    /**
77     * Database credentials - connection flags
78     * With the parameter flags you can set different connection options
79     * MYSQLI_CLIENT_COMPRESS - Use compression protocol
80     * MYSQLI_CLIENT_SSL - Use SSL (encryption)
81     * MULTI_STATEMENT flag is not supported in PHP
82     *
83     * @see https://www.php.net/manual/en/mysqli.real-connect.php
84     */
85    protected int $flags;
86
87    public function __construct(
88        string $host,
89        string $username,
90        string $passwd,
91        string $dbname,
92        ?int $port = null,
93        ?string $socket = null,
94        int $flags = 0,
95    ) {
96        $this->host = $host;
97        $this->username = $username;
98        $this->passwd = $passwd;
99        $this->dbname = $dbname;
100        $this->port = $port;
101        $this->socket = $socket;
102        $this->flags = $flags;
103    }
104
105    public function getHost(): string
106    {
107        return $this->host;
108    }
109
110    public function getUsername(): string
111    {
112        return $this->username;
113    }
114
115    public function getPasswd(): string
116    {
117        return $this->passwd;
118    }
119
120    public function getDbname(): string
121    {
122        return $this->dbname;
123    }
124
125    public function getPort(): ?int
126    {
127        return $this->port;
128    }
129
130    public function getSocket(): ?string
131    {
132        return $this->socket;
133    }
134
135    public function getFlags(): int
136    {
137        return $this->flags;
138    }
139}