Failed Conditions
Pull Request — master (#321)
by Anton
23:35 queued 08:33
created

application/models/Roles/Row.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link      https://github.com/bluzphp/skeleton
5
 */
6
7
declare(strict_types=1);
8
9
namespace Application\Roles;
10
11
use Bluz\Validator\Traits\Validator;
0 ignored issues
show
The type Bluz\Validator\Traits\Validator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * Row of User Role
15
 *
16
 * @package Application\Roles
17
 *
18
 * @property integer $id
19
 * @property string $name
20
 */
21
class Row extends \Bluz\Db\Row
0 ignored issues
show
The type Bluz\Db\Row was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
{
23
    use Validator;
24
25
    /**
26
     * {@inheritdoc}
27
     *
28
     * @throws \Bluz\Validator\Exception\ComponentException
29
     */
30
    protected function beforeInsert(): void
31
    {
32
        $this->addValidator('name')
33
            ->required()
34
            ->latin()
35
            ->callback(
36
                function ($name) {
37
                    return !Table::findRowWhere(['name' => $name]);
38
                }
39
            )
40
            ->setDescription('Role already exists');
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @throws \Bluz\Validator\Exception\ComponentException
47
     */
48
    protected function beforeUpdate(): void
49
    {
50
        $this->addValidator('name')
51
            ->required()
52
            ->latin()
53
            ->callback(
54
                function ($name) {
55
                    return !in_array(strtolower($name), Table::getInstance()->getBasicRoles(), false);
56
                },
57
                'Role is basic and can\'t be editable'
58
            )
59
            ->callback(
60
                function ($name) {
61
                    return $this->clean['name'] !== $name;
62
                },
63
                'Role name is the same as original'
64
            )
65
            ->callback(
66
                function ($name) {
67
                    return !Table::findRowWhere(['name' => $name]);
68
                },
69
                'Role already exists'
70
            );
71
    }
72
73
    /**
74
     * isBasic
75
     *
76
     * @return boolean
77
     */
78 1
    public function isBasic(): bool
79
    {
80 1
        return in_array(strtolower($this->name), Table::getInstance()->getBasicRoles(), false);
81
    }
82
}
83