Completed
Pull Request — master (#1)
by Christian
02:27
created

InverseFunctionalIdentifier::withMboxSha1Sum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
/**
15
 * The inverse functional identifier of an {@link Actor}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class InverseFunctionalIdentifier
20
{
21
    /**
22
     * @var string A mailto IRI
23
     */
24
    private $mbox;
25
26
    /**
27
     * @var string The SHA1 hash of a mailto IRI
28
     */
29
    private $mboxSha1Sum;
30
31
    /**
32
     * @var string An openID uniquely identifying an Agent
33
     */
34
    private $openId;
35
36
    /**
37
     * @var Account A user account on an existing system
38
     */
39
    private $account;
40
41
    /**
42
     * Use on of the with*() factory methods to obtain an InverseFunctionalIdentifier
43
     * instance.
44
     */
45
    private function __construct()
46
    {
47
    }
48
49
    public static function withMbox($mbox)
50
    {
51
        $iri = new InverseFunctionalIdentifier();
52
        $iri->mbox = $mbox;
53
54
        return $iri;
55
    }
56
57
    public static function withMboxSha1Sum($mboxSha1Sum)
58
    {
59
        $iri = new InverseFunctionalIdentifier();
60
        $iri->mboxSha1Sum = $mboxSha1Sum;
61
62
        return $iri;
63
    }
64
65
    public static function withOpenId($openId)
66
    {
67
        $iri = new InverseFunctionalIdentifier();
68
        $iri->openId = $openId;
69
70
        return $iri;
71
    }
72
73
    public static function withAccount($account)
74
    {
75
        $iri = new InverseFunctionalIdentifier();
76
        $iri->account = $account;
77
78
        return $iri;
79
    }
80
81
    /**
82
     * Checks if another IRI is equal.
83
     *
84
     * Two inverse functional identifiers are equal if and only if all of their
85
     * properties are equal.
86
     *
87
     * @param InverseFunctionalIdentifier $iri The iri to compare with
88
     *
89
     * @return bool True if the IRIs are equal, false otherwise
90
     */
91
    public function equals(InverseFunctionalIdentifier $iri)
92
    {
93
        if ($this->mbox !== $iri->mbox) {
94
            return false;
95
        }
96
97
        if ($this->mboxSha1Sum !== $iri->mboxSha1Sum) {
98
            return false;
99
        }
100
101
        if ($this->openId !== $iri->openId) {
102
            return false;
103
        }
104
105
        if (null === $this->account && null !== $iri->account) {
106
            return false;
107
        }
108
109
        if (null !== $this->account && null === $iri->account) {
110
            return false;
111
        }
112
113
        if (null !== $this->account && !$this->account->equals($iri->account)) {
114
            return false;
115
        }
116
117
        return true;
118
    }
119
120
    public function __toString()
121
    {
122
        if (null !== $this->mbox) {
123
            return $this->mbox;
124
        }
125
126
        if (null !== $this->mboxSha1Sum) {
127
            return $this->mboxSha1Sum;
128
        }
129
130
        if (null !== $this->openId) {
131
            return $this->openId;
132
        }
133
134
        return $this->account;
135
    }
136
}
137