Completed
Push — master ( 2b511a...1544c6 )
by Christian
10s
created

Activity   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 55
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 4 1
A getDefinition() 0 4 1
C equals() 0 24 9
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
 * An Activity in a {@link Statement}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Activity extends StatementObject
20
{
21
    private $id;
22
    private $definition;
23
24
    public function __construct(IRI $id, Definition $definition = null)
25
    {
26
        $this->id = $id;
27
        $this->definition = $definition;
28
    }
29
30
    /**
31
     * Returns the Activity's unique identifier.
32
     */
33
    public function getId(): IRI
34
    {
35
        return $this->id;
36 13
    }
37
38 13
    /**
39 13
     * Returns the Activity's {@link Definition}.
40 13
     */
41
    public function getDefinition(): ?Definition
42
    {
43
        return $this->definition;
44
    }
45
46
    /**
47 1
     * {@inheritdoc}
48
     */
49 1
    public function equals(StatementObject $object): bool
50
    {
51
        if (!$object instanceof Activity) {
52
            return false;
53
        }
54
55
        if (!$this->id->equals($object->id)) {
56
            return false;
57
        }
58
59
        if (null === $this->definition && null !== $object->definition) {
60
            return false;
61
        }
62
63
        if (null !== $this->definition && null === $object->definition) {
64
            return false;
65 2
        }
66
67 2
        if (null !== $this->definition && !$this->definition->equals($object->definition)) {
0 ignored issues
show
Bug introduced by
It seems like $object->definition can be null; however, equals() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
68
            return false;
69
        }
70
71
        return true;
72
    }
73
}
74