MySQLUserFactory::asDrop()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[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 FlexPHP\Database\Factories\User;
11
12
final class MySQLUserFactory extends AbstractUserFactory
13
{
14 7
    public function asCreate(): string
15
    {
16 7
        return \sprintf("CREATE USER '%s'@'%s' IDENTIFIED BY '%s';", $this->name, $this->host, $this->password);
17
    }
18
19 5
    public function asDrop(): string
20
    {
21 5
        return \sprintf("DROP USER '%s'@'%s';", $this->name, $this->host);
22
    }
23
24 28
    public function asPrivileges(): string
25
    {
26 28
        $privileges = [];
27
28 28
        foreach ($this->permissions as $permission) {
29 28
            $privileges[] = \sprintf(
30 28
                "GRANT %s ON %s.%s TO '%s'@'%s';",
31 28
                $permission['permission'],
32 28
                $permission['database'],
33 28
                $permission['table'],
34 28
                $this->name,
35 28
                $this->host
36
            );
37
        }
38
39 28
        return \implode("\n", $privileges);
40
    }
41
}
42