AbstractUserFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 57
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setPassword() 0 3 1
A setName() 0 5 1
A setHost() 0 7 2
A setGrant() 0 6 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
use FlexPHP\Database\Interfaces\UserFactoryInterface;
13
use FlexPHP\Database\Validations\NameUserValidation;
14
15
abstract class AbstractUserFactory implements UserFactoryInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $name;
21
22
    /**
23
     * @var string
24
     */
25
    protected $password;
26
27
    /**
28
     * @var string
29
     */
30
    protected $host;
31
32
    /**
33
     * @var array<int, array>
34
     */
35
    protected $permissions = [];
36
37 104
    public function setName(string $name): void
38
    {
39 104
        (new NameUserValidation($name))->validate();
40
41 101
        $this->name = $name;
42 101
    }
43
44 13
    public function setPassword(string $password): void
45
    {
46 13
        $this->password = $password;
47 13
    }
48
49 101
    public function setHost(string $host): void
50
    {
51 101
        if (empty(\trim($host))) {
52 6
            $host = '%';
53
        }
54
55 101
        $this->host = $host;
56 101
    }
57
58 80
    public function setGrant(string $permission, string $database = '*', string $table = '*'): void
59
    {
60 80
        $this->permissions[] = [
61 80
            'database' => $database,
62 80
            'table' => $table,
63 80
            'permission' => $permission,
64
        ];
65 80
    }
66
67
    abstract public function asCreate(): string;
68
69
    abstract public function asDrop(): string;
70
71
    abstract public function asPrivileges(): string;
72
}
73