Definition::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
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
 * 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
    public function __construct(array $name, array $description, $type)
40
    {
41
        $this->name = $name;
42
        $this->description = $description;
43
        $this->type = $type;
44
    }
45
46
    /**
47
     * Returns the human readable names.
48
     *
49
     * @return array The name language map
50
     */
51
    public function getName()
52
    {
53
        return $this->name;
54
    }
55
56
    /**
57
     * Returns the human readable descriptions.
58
     *
59
     * @return array The description language map
60
     */
61
    public function getDescription()
62
    {
63
        return $this->description;
64
    }
65
66
    /**
67
     * Returns the {@link Activity} type.
68
     *
69
     * @return string The type
70
     */
71
    public function getType()
72
    {
73
        return $this->type;
74
    }
75
76
    /**
77
     * Checks if another definition is equal.
78
     *
79
     * Two definitions are equal if and only if all of their properties are equal.
80
     *
81
     * @param Definition $definition The definition to compare with
82
     *
83
     * @return bool True if the definitions are equal, false otherwise
84
     */
85
    public function equals(Definition $definition)
86
    {
87
        if ($this->type !== $definition->type) {
88
            return false;
89
        }
90
91
        if (count($this->name) !== count($definition->name)) {
92
            return false;
93
        }
94
95
        if (count($this->description) !== count($definition->description)) {
96
            return false;
97
        }
98
99 View Code Duplication
        foreach ($this->name as $language => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
            if (!isset($definition->name[$language])) {
101
                return false;
102
            }
103
104
            if ($value !== $definition->name[$language]) {
105
                return false;
106
            }
107
        }
108
109 View Code Duplication
        foreach ($this->description as $language => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
            if (!isset($definition->description[$language])) {
111
                return false;
112
            }
113
114
            if ($value !== $definition->description[$language]) {
115
                return false;
116
            }
117
        }
118
119
        return true;
120
    }
121
}
122