Completed
Push — master ( 76469b...99b48b )
by Jan Philip
12:47
created

Year::getIterator()   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
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace JPBernius\FMeat\Entities;
4
5
use ArrayIterator;
6
use IteratorAggregate;
7
use Traversable;
8
9
/**
10
 * Class Year
11
 * @package JPBernius\FMeat\Entities
12
 */
13
class Year implements Entity, IteratorAggregate
14
{
15
    /** @var int */
16
    private $yearNumber;
17
18
    /** @var array */
19
    private $weeks = [];
20
21
    /**
22
     * Year constructor.
23
     * @param int|null $yearNumber
24
     */
25
    public function __construct(int $yearNumber = null)
26
    {
27
        if (is_null($yearNumber)) {
28
            $yearNumber = intval(date("Y"));
29
        }
30
31
        $this->yearNumber = $yearNumber;
32
    }
33
34
    /**
35
     * @param string $jsonString
0 ignored issues
show
Bug introduced by
There is no parameter named $jsonString. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
36
     * @return Year
37
     */
38
    public static function fromJson(\stdClass $jsonObject): self
39
    {
40
        return new Year($jsonObject->year);
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46
    public function getYearNumber(): int
47
    {
48
        return $this->yearNumber;
49
    }
50
51
    /**
52
     * @param Week $week
53
     */
54
    public function addWeek(Week $week): void
55
    {
56
        $this->weeks[$week->getWeekNumber() - 1] = $week;
57
    }
58
59
    /**
60
     * @param int $weekNumber
61
     * @return Week
62
     */
63
    public function getWeek(int $weekNumber): Week
64
    {
65
        if (empty($this->weeks[$weekNumber])) {
66
            return null;
67
        }
68
69
        return $this->weeks[$weekNumber];
70
    }
71
72
    /**
73
     * Retrieve an external iterator
74
     * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
75
     * @return Traversable An instance of an object implementing <b>Iterator</b> or
76
     * <b>Traversable</b>
77
     * @since 5.0.0
78
     */
79
    public function getIterator(): Traversable
80
    {
81
        return new ArrayIterator($this->weeks);
82
    }
83
}