SequencingInteractionDefinition::equals()   B
last analyzed

Complexity

Conditions 9
Paths 8

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.0555
c 0
b 0
f 0
cc 9
nc 8
nop 1
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\Interaction;
13
14
use Xabbuh\XApi\Model\Definition;
15
use Xabbuh\XApi\Model\Extensions;
16
use Xabbuh\XApi\Model\IRI;
17
use Xabbuh\XApi\Model\IRL;
18
use Xabbuh\XApi\Model\LanguageMap;
19
20
/**
21
 * An interaction where the learner is asked to order items in a set.
22
 *
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
final class SequencingInteractionDefinition extends InteractionDefinition
26
{
27
    private $choices;
28
29
    /**
30
     * @param string[]|null               $correctResponsesPattern
31
     * @param InteractionComponent[]|null $choices
32
     */
33
    public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $choices = null)
34
    {
35
        parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
36
37
        $this->choices = $choices;
38
    }
39
40
    /**
41
     * @param InteractionComponent[]|null $choices
42
     */
43
    public function withChoices(array $choices = null): self
44
    {
45
        $interaction = clone $this;
46
        $interaction->choices = $choices;
47
48
        return $interaction;
49
    }
50
51
    /**
52
     * @return InteractionComponent[]|null
53
     */
54
    public function getChoices(): ?array
55
    {
56
        return $this->choices;
57
    }
58
59
    public function equals(Definition $definition): bool
60
    {
61
        if (!parent::equals($definition)) {
62
            return false;
63
        }
64
65
        if (!$definition instanceof SequencingInteractionDefinition) {
66
            return false;
67
        }
68
69
        if (null !== $this->choices xor null !== $definition->choices) {
70
            return false;
71
        }
72
73
        if (null !== $this->choices) {
74
            if (count($this->choices) !== count($definition->choices)) {
75
                return false;
76
            }
77
78
            foreach ($this->choices as $key => $choice) {
79
                if (!isset($definition->choices[$key])) {
80
                    return false;
81
                }
82
83
                if (!$choice->equals($definition->choices[$key])) {
84
                    return false;
85
                }
86
            }
87
        }
88
89
        return true;
90
    }
91
}
92