Initiator::cacheDayOfWeek()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Andegna\Operations;
4
5
use Andegna\Converter\Converter;
6
use Andegna\Converter\FromJdnConverter;
7
use Andegna\Validator\LeapYearValidator;
8
use DateTime as GregorianDateTime;
9
10
/**
11
 * Initiator trait.
12
 */
13
trait Initiator
14
{
15
    /**
16
     * This fields are just for catching.
17
     *
18
     * @return void
19
     */
20 49
    protected function updateComputedFields()
21
    {
22
        // Julian Date Number of the available datetime
23 49
        $jdn = $this->getJdnFromBase($this->dateTime);
0 ignored issues
show
Bug introduced by
The property dateTime does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
25 49
        $converter = new FromJdnConverter($jdn);
26
27 49
        $this->setDateFromConverter($converter);
28 49
        $this->cacheTimestamp();
29 49
        $this->computeFields();
30 49
    }
31
32
    /**
33
     * Return the JDN of the given gregorian date time.
34
     *
35
     * @param GregorianDateTime $dateTime
36
     *
37
     * @return int
38
     */
39 49
    protected function getJdnFromBase(GregorianDateTime $dateTime): int
40
    {
41 49
        $year = $dateTime->format('Y');
42 49
        $month = $dateTime->format('m');
43 49
        $day = $dateTime->format('d');
44
45 49
        return gregoriantojd($month, $day, $year);
46
    }
47
48
    /**
49
     * Set the converted year, month and day from the given converter.
50
     *
51
     * @param Converter $converter
52
     *
53
     * @return void
54
     */
55 49
    protected function setDateFromConverter(Converter $converter)
56
    {
57 49
        $this->year = $converter->getYear();
0 ignored issues
show
Bug introduced by
The property year does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
58 49
        $this->month = $converter->getMonth();
0 ignored issues
show
Bug introduced by
The property month does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
59 49
        $this->day = $converter->getDay();
0 ignored issues
show
Bug introduced by
The property day does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60 49
    }
61
62
    /**
63
     * Set the timestamp field.
64
     */
65 49
    protected function cacheTimestamp()
66
    {
67 49
        $this->timestamp = $this->dateTime->getTimestamp();
0 ignored issues
show
Bug introduced by
The property timestamp does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
68 49
    }
69
70
    /**
71
     * Computer the available properties.
72
     *
73
     * @return void
74
     */
75 49
    protected function computeFields()
76
    {
77 49
        $this->computeLeapYear();
78 49
        $this->computeDayOfYear();
79 49
        $this->computeDaysInMonth();
80 49
        $this->cacheDayOfWeek();
81 49
    }
82
83
    /**
84
     * Compute the leapYear property.
85
     *
86
     * @return void
87
     */
88 49
    protected function computeLeapYear()
89
    {
90 49
        $leapYear = new LeapYearValidator($this->year);
91
92 49
        $this->leapYear = $leapYear->isValid();
0 ignored issues
show
Bug introduced by
The property leapYear does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
93 49
    }
94
95
    /**
96
     * Compute the dayOfYear property.
97
     *
98
     * @return void
99
     */
100 49
    protected function computeDayOfYear()
101
    {
102 49
        $this->dayOfYear = ($this->month - 1) * 30 + $this->day;
0 ignored issues
show
Bug introduced by
The property dayOfYear does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103 49
    }
104
105
    /**
106
     * Compute the daysInMonth property.
107
     *
108
     * @return void
109
     */
110 49
    protected function computeDaysInMonth()
111
    {
112 49
        $this->daysInMonth = $this->month === 13 ? ($this->leapYear ? 6 : 5) : 30;
0 ignored issues
show
Bug introduced by
The property daysInMonth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
113 49
    }
114
115
    /**
116
     * cache the dayOfWeek property.
117
     *
118
     * @return void
119
     */
120 49
    protected function cacheDayOfWeek()
121
    {
122 49
        $this->dayOfWeek = (int) $this->dateTime->format('N');
0 ignored issues
show
Bug introduced by
The property dayOfWeek does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
123 49
    }
124
}
125