Completed
Push — master ( 6a6782...6e04b4 )
by Samson
01:03
created

ToJdnConverter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 16 2
A process() 0 8 1
1
<?php
2
3
namespace Andegna\Converter;
4
5
use Andegna\Exception\InvalidDateException;
6
use Andegna\Validator\DateValidator as DateValidator;
7
8
class ToJdnConverter extends Converter
9
{
10
    public function __construct($day, $month, $year)
11
    {
12
        $this->set($day, $month, $year);
13
    }
14
15
    public function set($day, $month, $year)
16
    {
17
        $validator = new DateValidator($day, $month, $year);
18
19
        if (!$validator->isValid()) {
20
            throw new InvalidDateException();
21
        }
22
23
        $this->day = $day;
24
        $this->month = $month;
25
        $this->year = $year;
26
27
        $this->jdn = static::process($day, $month, $year);
28
29
        return $this;
30
    }
31
32
    public static function process($day, $month, $year)
33
    {
34
        return (1723856 + 365) +
35
            365 * ($year - 1) +
36
            (int) ($year / 4) +
37
            30 * $month +
38
            $day - 31;
39
    }
40
}
41