Completed
Pull Request — master (#27)
by Christian
03:12
created

Interaction::getCorrectResponsesPattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Interaction;
13
14
use Xabbuh\XApi\Model\Definition;
15
use Xabbuh\XApi\Model\LanguageMap;
16
17
abstract class Interaction extends Definition
18
{
19
    private $correctResponsesPattern;
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
     */
28
    public function __construct(LanguageMap $name = null, LanguageMap $description = null, $type = null, $moreInfo = null, array $correctResponsesPattern = null)
29
    {
30
        parent::__construct($name, $description, $type, $moreInfo);
31
32
        $this->correctResponsesPattern = $correctResponsesPattern;
33
    }
34
35
    /**
36
     * @param string[]|null $correctResponsesPattern
37
     *
38
     * @return static
39
     */
40
    public function withCorrectResponsesPattern(array $correctResponsesPattern = null)
41
    {
42
        $interaction = clone $this;
43
        $interaction->correctResponsesPattern = $correctResponsesPattern;
44
45
        return $interaction;
46
    }
47
48
    public function getCorrectResponsesPattern()
49
    {
50
        return $this->correctResponsesPattern;
51
    }
52
53
    public function equals(Definition $definition)
54
    {
55
        if (!parent::equals($definition)) {
56
            return false;
57
        }
58
59
        if (!$definition instanceof Interaction) {
60
            return false;
61
        }
62
63
        if (null !== $this->correctResponsesPattern xor null !== $definition->correctResponsesPattern) {
64
            return false;
65
        }
66
67
        if (null !== $this->correctResponsesPattern) {
68
            if (count($this->correctResponsesPattern) !== count($definition->correctResponsesPattern)) {
69
                return false;
70
            }
71
72
            foreach ($this->correctResponsesPattern as $value) {
73
                if (!in_array($value, $definition->correctResponsesPattern, true)) {
74
                    return false;
75
                }
76
            }
77
        }
78
79
        return true;
80
    }
81
}
82