Completed
Pull Request — master (#27)
by Christian
02:44
created

PerformanceInteractionDefinition::withSteps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
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\LanguageMap;
16
17
final class PerformanceInteractionDefinition extends InteractionDefinition
18
{
19
    private $steps;
20
21
    /**
22
     * @param LanguageMap|null            $name
23
     * @param LanguageMap|null            $description
24
     * @param string|null                 $type
25
     * @param string|null                 $moreInfo
26
     * @param string[]|null               $correctResponsesPattern
27
     * @param InteractionComponent[]|null $steps
28
     */
29
    public function __construct(LanguageMap $name = null, LanguageMap $description = null, $type = null, $moreInfo = null, array $correctResponsesPattern = null, array $steps = null)
30
    {
31
        parent::__construct($name, $description, $type, $moreInfo, $correctResponsesPattern);
32
33
        $this->steps = $steps;
34
    }
35
36
    /**
37
     * @param InteractionComponent[]|null $steps
38
     *
39
     * @return static
40
     */
41
    public function withSteps(array $steps = null)
42
    {
43
        $interaction = clone $this;
44
        $interaction->steps = $steps;
45
46
        return $interaction;
47
    }
48
49
    public function getSteps()
50
    {
51
        return $this->steps;
52
    }
53
54
    public function equals(Definition $definition)
55
    {
56
        if (!parent::equals($definition)) {
57
            return false;
58
        }
59
60
        if (!$definition instanceof PerformanceInteractionDefinition) {
61
            return false;
62
        }
63
64
        if (null !== $this->steps xor null !== $definition->steps) {
65
            return false;
66
        }
67
68
        if (null !== $this->steps) {
69
            if (count($this->steps) !== count($definition->steps)) {
70
                return false;
71
            }
72
73
            foreach ($this->steps as $key => $step) {
74
                if (!isset($definition->steps[$key])) {
75
                    return false;
76
                }
77
78
                if (!$step->equals($definition->steps[$key])) {
79
                    return false;
80
                }
81
            }
82
        }
83
84
        return true;
85
    }
86
}
87