Achievement::points()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zurbaev\Achievements;
4
5
class Achievement
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $data = [];
11
12
    /**
13
     * Achievement constructor.
14
     *
15
     * @param array $data
16
     */
17
    public function __construct(array $data)
18
    {
19
        $this->data = $data;
20
    }
21
22
    /**
23
     * Achievement ID.
24
     *
25
     * @return mixed|null
26
     */
27
    public function id()
28
    {
29
        return $this->data['id'] ?? null;
30
    }
31
32
    /**
33
     * Achievement points.
34
     *
35
     * @return int
36
     */
37
    public function points(): int
38
    {
39
        return intval($this->data['points'] ?? 0);
40
    }
41
42
    /**
43
     * Achievement criterias.
44
     *
45
     * @return array
46
     */
47 View Code Duplication
    public function criterias(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
48
    {
49
        if (!isset($this->data['criterias']) || !is_array($this->data['criterias'])) {
50
            return [];
51
        }
52
53
        return $this->data['criterias'];
54
    }
55
56
    /**
57
     * Determines if achievement was already completed.
58
     *
59
     * @return bool
60
     */
61
    public function completed(): bool
62
    {
63
        return boolval($this->data['completed'] ?? false);
64
    }
65
66
    /**
67
     * Achievement criteria IDs.
68
     *
69
     * @return array
70
     */
71
    public function criteriaIds(): array
72
    {
73
        return array_map(function (AchievementCriteria $criteria) {
74
            return $criteria->id();
75
        }, $this->criterias());
76
    }
77
}
78