MySQLUserFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A asPrivileges() 0 16 2
A asDrop() 0 3 1
A asCreate() 0 3 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