MySQLUserFactory::asPrivileges()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
ccs 11
cts 11
cp 1
cc 2
nc 2
nop 0
crap 2
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