Completed
Push — master ( 2883f1...b12947 )
by Christian
11s
created

Actor   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 79
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getInverseFunctionalIdentifier() 0 4 1
A getName() 0 4 1
C equals() 0 24 8
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 Actor of a {@link Statement}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
abstract class Actor extends Object
20
{
21
    /**
22
     * The actor's {@link InverseFunctionalIdentifier inverse functional identifier}
23
     *
24
     * @var InverseFunctionalIdentifier|null
25
     */
26
    private $iri;
27
28
    /**
29
     * Name of the {@link Agent} or {@link Group}
30
     * @var string|null
31
     */
32
    private $name;
33
34
    /**
35
     * @param InverseFunctionalIdentifier|null $iri
36
     * @param string|null                      $name
37
     */
38 15
    public function __construct(InverseFunctionalIdentifier $iri = null, $name = null)
39
    {
40 15
        $this->iri = $iri;
41 15
        $this->name = $name;
42 15
    }
43
44
    /**
45
     * Returns the Actor's {@link InverseFunctionalIdentifier inverse functional identifier}.
46
     *
47
     * @return InverseFunctionalIdentifier|null The inverse functional identifier
48
     */
49 19
    public function getInverseFunctionalIdentifier()
50
    {
51 19
        return $this->iri;
52
    }
53
54
    /**
55
     * Returns the name of the {@link Agent} or {@link Group}.
56
     *
57
     * @return string|null The name
58
     */
59
    public function getName()
60
    {
61
        return $this->name;
62
    }
63
64
    /**
65
     * Checks if another actor is equal.
66
     *
67
     * Two actors are equal if and only if all of their properties are equal.
68
     *
69
     * @param Object $actor The actor to compare with
70
     *
71
     * @return bool True if the actors are equal, false otherwise
72
     */
73 26
    public function equals(Object $actor)
74
    {
75 26
        if (!parent::equals($actor)) {
76 7
            return false;
77
        }
78
79 20
        if (!$actor instanceof Actor) {
80 1
            return false;
81
        }
82
83 19
        if ($this->name !== $actor->name) {
84 14
            return false;
85
        }
86
87 5
        if (null !== $this->iri xor null !== $actor->iri) {
88
            return false;
89
        }
90
91
        if (null !== $this->iri && null !== $actor->iri && !$this->iri->equals($actor->iri)) {
92
            return false;
93
        }
94
95
        return true;
96
    }
97
}
98