Completed
Branch release/5.5.0 (ca3c12)
by Schlaefer
04:35
created

Resources::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Saito\User\Permission;
14
15
use Saito\User\Permission\Resource;
16
17
class Resources
18
{
19
    /** @var \Saito\User\Permission\Resource[] Resources */
20
    protected $resources = [];
21
22
    /**
23
     * Add resource
24
     *
25
     * @param \Saito\User\Permission\Resource $resource Resource to add
26
     * @return self
27
     */
28
    public function add(Resource $resource): self
29
    {
30
        $this->resources[$resource->getName()] = $resource;
31
32
        return $this;
33
    }
34
35
    /**
36
     * Get resource
37
     *
38
     * @param string $resouce Name of resource to get
39
     * @return \Saito\User\Permission\Resource|null Resource or null of resource not found
40
     */
41
    public function get(string $resouce): ?Resource
42
    {
43
        return $this->resources[$resouce] ?? null;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function __clone()
50
    {
51
        foreach ($this->resources as $key => $resource) {
52
            $this->resources[$key] = clone $resource;
53
        }
54
    }
55
}
56