Target   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 56
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getId() 0 4 1
A getType() 0 4 1
A __toString() 0 4 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Caridea
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2018 LibreWorks contributors
19
 * @license   Apache-2.0
20
 */
21
namespace Caridea\Acl;
22
23
/**
24
 * Immutable reference to a domain object.
25
 *
26
 * @copyright 2015-2018 LibreWorks contributors
27
 * @license   Apache-2.0
28
 */
29
class Target
30
{
31
    /**
32
     * @var string The resource type
33
     */
34
    private $type;
35
    /**
36
     * @var mixed The resource identifier
37
     */
38
    private $id;
39
40
    /**
41
     * Creates a new Target.
42
     *
43
     * @param string $type The resource type
44
     * @param mixed $id The resource identifier
45
     */
46 3
    public function __construct(string $type, $id)
47
    {
48 3
        $this->type = (string) $type;
49 3
        if (strlen(trim($this->type)) == 0) {
50 1
            throw new \InvalidArgumentException("Target type can't be blank");
51
        }
52 2
        $this->id = $id;
53 2
    }
54
    
55
    /**
56
     * Gets the identifier of the resource, usually a unique key.
57
     *
58
     * @return mixed The resource identifier
59
     */
60 1
    public function getId()
61
    {
62 1
        return $this->id;
63
    }
64
65
    /**
66
     * Gets the type of resource, usually a domain class name.
67
     *
68
     * @return string The resource type
69
     */
70 1
    public function getType(): string
71
    {
72 1
        return $this->type;
73
    }
74
    
75
    /**
76
     * A string representation of this object.
77
     *
78
     * @return string The string representation
79
     */
80 1
    public function __toString(): string
81
    {
82 1
        return "{$this->type}#{$this->id}";
83
    }
84
}
85