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

ToJdnConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 16 2
A process() 0 9 1
1
<?php
2
3
namespace Andegna\Converter;
4
5
use Andegna\Exception\InvalidDateException;
6
use Andegna\Validator\DateValidator as DateValidator;
7
8
/**
9
 * ToJdnConverter
10
 *
11
 * @package Andegna\Converter
12
 */
13
class ToJdnConverter extends Converter
14
{
15
16
    /**
17
     * ToJdnConverter constructor.
18
     *
19
     * @param $day
20
     * @param $month
21
     * @param $year
22
     *
23
     * @throws \Andegna\Exception\InvalidDateException
24
     */
25
    public function __construct($day, $month, $year)
26
    {
27
        $this->set($day, $month, $year);
28
    }
29
30
    /**
31
     * @param $day
32
     * @param $month
33
     * @param $year
34
     *
35
     * @return $this
36
     * @throws \Andegna\Exception\InvalidDateException
37
     */
38
    public function set($day, $month, $year)
39
    {
40
        $validator = new DateValidator($day, $month, $year);
41
42
        if (!$validator->isValid()) {
43
            throw new InvalidDateException();
44
        }
45
46
        $this->day = $day;
47
        $this->month = $month;
48
        $this->year = $year;
49
50
        $this->jdn = static::process($day, $month, $year);
0 ignored issues
show
Documentation Bug introduced by
The property $jdn was declared of type integer, but static::process($day, $month, $year) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
51
52
        return $this;
53
    }
54
55
    protected static function process($day, $month, $year)
56
    {
57
        return
58
            (1723856 + 365) +
59
            365 * ($year - 1) +
60
            (int)($year / 4) +
61
            30 * $month +
62
            $day - 31;
63
    }
64
}
65