Completed
Push — master ( 1544c6...bf0179 )
by Christian
04:16
created

Person::getAccounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
 * Combined informations from multiple {@link Agent agents}.
16
 *
17
 * @author Jérôme Parmentier <[email protected]>
18
 */
19
final class Person
20
{
21
    /**
22
     * @var string[] List of names of Agents
23
     */
24
    private $names = array();
25
26
    /**
27
     * @var IRI[] List of mailto IRIs of Agents
28
     */
29
    private $mboxes = array();
30
31
    /**
32
     * @var string[] List of the SHA1 hashes of mailto IRIs of Agents
33
     */
34
    private $mboxSha1Sums = array();
35
36
    /**
37
     * @var string[] List of openids that uniquely identify the Agents
38
     */
39
    private $openIds = array();
40
41
    /**
42
     * @var Account[] List of accounts of Agents
43
     */
44
    private $accounts = array();
45
46
    private function __construct()
47
    {
48
    }
49
50
    /**
51
     * @param Agent[] $agents
52
     *
53
     * @return $this
54
     */
55
    public static function createFromAgents(array $agents)
56
    {
57
        $person = new self();
58
59
        foreach ($agents as $agent) {
60
            $iri = $agent->getInverseFunctionalIdentifier();
61
62
            if (null !== $mbox = $iri->getMbox()) {
63
                $person->mboxes[] = $mbox;
64
            }
65
66
            if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) {
67
                $person->mboxSha1Sums[] = $mboxSha1Sum;
68
            }
69
70
            if (null !== $openId = $iri->getOpenId()) {
71
                $person->openIds[] = $openId;
72
            }
73
74
            if (null !== $account = $iri->getAccount()) {
75
                $person->accounts[] = $account;
76
            }
77
78
            if (null !== $name = $agent->getName()) {
79
                $person->names[] = $name;
80
            }
81
        }
82
83
        return $person;
84
    }
85
86
    public function getNames()
87
    {
88
        return $this->names;
89
    }
90
91
    public function getMboxes()
92
    {
93
        return $this->mboxes;
94
    }
95
96
    public function getMboxSha1Sums()
97
    {
98
        return $this->mboxSha1Sums;
99
    }
100
101
    public function getOpenIds()
102
    {
103
        return $this->openIds;
104
    }
105
106
    public function getAccounts()
107
    {
108
        return $this->accounts;
109
    }
110
}
111