GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EntityId::equals()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Workflow library.
5
 *
6
 * @package    workflow
7
 * @author     David Molineus <[email protected]>
8
 * @copyright  2014-2017 netzmacht David Molineus
9
 * @license    LGPL 3.0 https://github.com/netzmacht/workflow
10
 * @filesource
11
 */
12
13
declare(strict_types=1);
14
15
namespace Netzmacht\Workflow\Data;
16
17
use Assert\Assertion;
18
19
/**
20
 * Class EntityId identifies an entity by using its row id and provider name.
21
 *
22
 * @package Netzmacht\Workflow\Data
23
 */
24
final class EntityId
25
{
26
    /**
27
     * The identifier. Usually a database id.
28
     *
29
     * @var mixed
30
     */
31
    private $identifier;
32
33
    /**
34
     * The provider name. Usually the database table name.
35
     *
36
     * @var string
37
     */
38
    private $providerName;
39
40
    /**
41
     * Construct.
42
     *
43
     * @param string $providerName The provider name.
44
     * @param mixed  $identifier   The identifier.
45
     */
46
    private function __construct(string $providerName, $identifier)
47
    {
48
        // cast to int, but not for uuids
49
        if (is_numeric($identifier)) {
50
            $identifier = (int) $identifier;
51
        }
52
53
        $this->providerName = $providerName;
54
        $this->identifier   = $identifier;
55
    }
56
57
    /**
58
     * Great the entity id from an string.
59
     *
60
     * @param string $entityId Entity id as string representation. For example provider::2.
61
     *
62
     * @return static
63
     */
64
    public static function fromString(string $entityId): self
65
    {
66
        list($providerName, $identifier) = explode('::', $entityId, 2);
67
68
        Assertion::notEmpty($providerName);
69
        Assertion::notEmpty($identifier);
70
71
        return new static($providerName, $identifier);
72
    }
73
74
    /**
75
     * Create the entity id by provider name and identifier.
76
     *
77
     * @param string $providerName The provider name.
78
     * @param mixed  $identifier   The identifier.
79
     *
80
     * @return static
81
     */
82
    public static function fromProviderNameAndId(string $providerName, $identifier): self
83
    {
84
        return new static($providerName, $identifier);
85
    }
86
87
    /**
88
     * Get the identifier.
89
     *
90
     * @return mixed
91
     */
92
    public function getIdentifier()
93
    {
94
        return $this->identifier;
95
    }
96
97
    /**
98
     * Get the provider name.
99
     *
100
     * @return string
101
     */
102
    public function getProviderName(): string
103
    {
104
        return $this->providerName;
105
    }
106
107
    /**
108
     * Consider if it is equal with another entity id.
109
     *
110
     * @param EntityId $entityId The entity id to compare with.
111
     *
112
     * @return bool
113
     */
114
    public function equals(EntityId $entityId): bool
115
    {
116
        return ((string) $this == (string) $entityId);
117
    }
118
119
    /**
120
     * Cast entity id to string.
121
     *
122
     * @return string
123
     */
124
    public function __toString(): string
125
    {
126
        return $this->providerName . '::' . $this->identifier;
127
    }
128
}
129