Passed
Push — develop ( 483e3b...adf527 )
by nguereza
03:31
created

Role::setUsers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine Framework
5
 *
6
 * Platine Framework is a lightweight, high-performance, simple and elegant
7
 * PHP Web framework
8
 *
9
 * This content is released under the MIT License (MIT)
10
 *
11
 * Copyright (c) 2020 Platine Framework
12
 *
13
 * Permission is hereby granted, free of charge, to any person obtaining a copy
14
 * of this software and associated documentation files (the "Software"), to deal
15
 * in the Software without restriction, including without limitation the rights
16
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
 * copies of the Software, and to permit persons to whom the Software is
18
 * furnished to do so, subject to the following conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all
21
 * copies or substantial portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
 * SOFTWARE.
30
 */
31
32
/**
33
 *  @file Role.php
34
 *
35
 *  The Role/group Entity class
36
 *
37
 *  @package    Platine\Framework\Auth\Entity
38
 *  @author Platine Developers team
39
 *  @copyright  Copyright (c) 2020
40
 *  @license    http://opensource.org/licenses/MIT  MIT License
41
 *  @link   https://www.platine-php.com
42
 *  @version 1.0.0
43
 *  @filesource
44
 */
45
46
declare(strict_types=1);
47
48
namespace Platine\Framework\Auth\Entity;
49
50
use Platine\Orm\Entity;
51
use Platine\Orm\Mapper\EntityMapperInterface;
52
53
/**
54
 * @class Role
55
 * @package Platine\Framework\Auth\Entity
56
 * @extends Entity<Role>
57
 */
58
class Role extends Entity
59
{
60
    /**
61
     *
62
     * @param EntityMapperInterface<Role> $mapper
63
     * @return void
64
     */
65
    public static function mapEntity(EntityMapperInterface $mapper): void
66
    {
67
        $mapper->relation('users')->shareMany(User::class);
68
        $mapper->relation('permissions')->shareMany(Permission::class);
69
        $mapper->useTimestamp();
70
        $mapper->casts([
71
            'created_at' => 'date',
72
            'updated_at' => '?date',
73
        ]);
74
    }
75
76
    /**
77
     * Set permissions
78
     * @param Permission[] $permissions
79
     * @return $this
80
     */
81
    public function setPermissions(array $permissions): self
82
    {
83
        foreach ($permissions as $permission) {
84
            $this->mapper()->link('permissions', $permission);
85
        }
86
87
        return $this;
88
    }
89
90
    /**
91
     * Remove permissions
92
     * @param Permission[] $permissions
93
     * @return $this
94
     */
95
    public function removePermissions(array $permissions): self
96
    {
97
        foreach ($permissions as $permission) {
98
            $this->mapper()->unlink('permissions', $permission);
99
        }
100
101
        return $this;
102
    }
103
104
    /**
105
     * Set users
106
     * @param User[] users
0 ignored issues
show
Bug introduced by
The type Platine\Framework\Auth\Entity\users 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...
107
     * @return $this
108
     */
109
    public function setUsers(array $users): self
110
    {
111
        foreach ($users as $user) {
112
            $this->mapper()->link('users', $user);
113
        }
114
115
        return $this;
116
    }
117
118
    /**
119
     * Remove users
120
     * @param User[] users
121
     * @return $this
122
     */
123
    public function removeUsers(array $users): self
124
    {
125
        foreach ($users as $user) {
126
            $this->mapper()->unlink('users', $user);
127
        }
128
129
        return $this;
130
    }
131
}
132