Test Failed
Branch develop (09cda0)
by Samson
03:06
created

Initiator::computeDaysInMonth()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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 BaseDateTime;
9
10
trait Initiator
11
{
12
    /**
13
     * This fields are just for catching.
14
     *
15
     * @return void
16
     */
17
    protected function updateComputedFields()
18
    {
19
        // Julian Date Number of the available datetime
20
        $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...
21
22
        $converter = new FromJdnConverter($jdn);
23
24
        $this->setDateFromConverter($converter);
25
        $this->cacheTimestamp();
26
        $this->computeFields();
27
    }
28
29
    /**
30
     * Return the JDN of the given gregorian date time.
31
     *
32
     * @param BaseDateTime $dateTime
33
     *
34
     * @return int
35
     */
36
    protected function getJdnFromBase(BaseDateTime $dateTime)
37
    {
38
        $year = $dateTime->format('Y');
39
        $month = $dateTime->format('m');
40
        $day = $dateTime->format('d');
41
42
        return gregoriantojd($month, $day, $year);
43
    }
44
45
    /**
46
     * Set the converted year, month and day from the given converter.
47
     *
48
     * @param Converter $converter
49
     *
50
     * @return void
51
     */
52
    protected function setDateFromConverter(Converter $converter)
53
    {
54
        $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...
55
        $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...
56
        $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...
57
    }
58
59
    /**
60
     * Set the timestamp field
61
     */
62
    protected function cacheTimestamp()
63
    {
64
        $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...
65
    }
66
67
    /**
68
     * Computer the available properties.
69
     *
70
     * @return void
71
     */
72
    protected function computeFields()
73
    {
74
        $this->computeLeapYear();
75
        $this->computeDayOfYear();
76
        $this->computeDaysInMonth();
77
        $this->cacheDayOfWeek();
78
    }
79
80
    /**
81
     * Compute the leapYear property.
82
     *
83
     * @return void
84
     */
85
    protected function computeLeapYear()
86
    {
87
        $leapYear = new LeapYearValidator($this->year);
88
89
        $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...
90
    }
91
92
    /**
93
     * Compute the dayOfYear property.
94
     *
95
     * @return void
96
     */
97
    protected function computeDayOfYear()
98
    {
99
        $this->dayOfYear = ($this->month - 1) * 30 + ($this->day - 1);
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...
100
    }
101
102
    /**
103
     * Compute the daysInMonth property.
104
     *
105
     * @return void
106
     */
107
    protected function computeDaysInMonth()
108
    {
109
        if ($this->month === 13) {
110
            $this->daysInMonth = $this->leapYear ? 6 : 5;
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...
111
        }
112
113
        $this->daysInMonth = 30;
114
    }
115
116
    /**
117
     * cache the dayOfWeek property.
118
     *
119
     * @return void
120
     */
121
    protected function cacheDayOfWeek()
122
    {
123
        $this->dayOfWeek = intval($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...
124
    }
125
126
}
127