Completed
Pull Request — master (#8)
by Christian
02:48
created

Definition   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 16
c 8
b 0
f 1
lcom 1
cbo 0
dl 0
loc 131
rs 10
ccs 0
cts 47
cp 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getName() 0 4 1
A getDescription() 0 4 1
A getType() 0 4 1
A getMoreInfo() 0 4 1
C equals() 0 40 11
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
 * Definition of an {@link Activity}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Definition
20
{
21
    /**
22
     * The human readable activity name
23
     * @var array
24
     */
25
    private $name;
26
27
    /**
28
     * The human readable activity description
29
     * @var array
30
     */
31
    private $description;
32
33
    /**
34
     * The type of the {@link Activity}
35
     * @var string
36
     */
37
    private $type;
38
39
    /**
40
     * An IRL where human-readable information describing the {@link Activity} can be found.
41
     *
42
     * @var string|null
43
     */
44
    private $moreInfo;
45
46
    /**
47
     * @param array|null  $name
48
     * @param array|null  $description
49
     * @param string|null $type
50
     * @param string|null $moreInfo
51
     */
52
    public function __construct(array $name = null, array $description = null, $type = null, $moreInfo = null)
53
    {
54
        $this->name = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name can be null. However, the property $name is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
55
        $this->description = $description;
0 ignored issues
show
Documentation Bug introduced by
It seems like $description can be null. However, the property $description is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
56
        $this->type = $type;
57
        $this->moreInfo = $moreInfo;
58
    }
59
60
    /**
61
     * Returns the human readable names.
62
     *
63
     * @return array The name language map
64
     */
65
    public function getName()
66
    {
67
        return $this->name;
68
    }
69
70
    /**
71
     * Returns the human readable descriptions.
72
     *
73
     * @return array The description language map
74
     */
75
    public function getDescription()
76
    {
77
        return $this->description;
78
    }
79
80
    /**
81
     * Returns the {@link Activity} type.
82
     *
83
     * @return string The type
84
     */
85
    public function getType()
86
    {
87
        return $this->type;
88
    }
89
90
    /**
91
     * Returns an IRL where human-readable information about the activity can be found.
92
     *
93
     * @return string|null
94
     */
95
    public function getMoreInfo()
96
    {
97
        return $this->moreInfo;
98
    }
99
100
    /**
101
     * Checks if another definition is equal.
102
     *
103
     * Two definitions are equal if and only if all of their properties are equal.
104
     *
105
     * @param Definition $definition The definition to compare with
106
     *
107
     * @return bool True if the definitions are equal, false otherwise
108
     */
109
    public function equals(Definition $definition)
110
    {
111
        if ($this->type !== $definition->type) {
112
            return false;
113
        }
114
115
        if ($this->moreInfo !== $definition->moreInfo) {
116
            return false;
117
        }
118
119
        if (count($this->name) !== count($definition->name)) {
120
            return false;
121
        }
122
123
        if (count($this->description) !== count($definition->description)) {
124
            return false;
125
        }
126
127
        foreach ($this->name as $language => $value) {
128
            if (!isset($definition->name[$language])) {
129
                return false;
130
            }
131
132
            if ($value !== $definition->name[$language]) {
133
                return false;
134
            }
135
        }
136
137
        foreach ($this->description as $language => $value) {
138
            if (!isset($definition->description[$language])) {
139
                return false;
140
            }
141
142
            if ($value !== $definition->description[$language]) {
143
                return false;
144
            }
145
        }
146
147
        return true;
148
    }
149
}
150