Completed
Push — master ( ae829f...1d5438 )
by Laurent
23s
created

TimeHelper::getEaster()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 3
eloc 15
nc 4
nop 1
1
<?php
2
/**
3
 * TimeHelper Helpers pour les dates de l'application GLSR.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version since 1.0.0
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Helper;
16
17
/**
18
 * Time helper.
19
 *
20
 * @category Helper
21
 */
22
class TimeHelper
23
{
24
    /**
25
     * get Easter date.
26
     *
27
     * @param integer $pYear
28
     * @return timestamp
29
     */
30
    private function getEaster($pYear = null)
31
    {
32
        if (is_null($pYear)) {
33
            $pYear = (int)date('Y');
34
        }
35
        $nDate = $pYear - 1900;
36
        $pAa = $nDate%19;
37
        $pBb = floor(((7*$pAa)+1)/19);
38
        $pCc = ((11*$pAa)-$pBb+4)%29;
39
        $pDd = floor($nDate/4);
40
        $pEe = ($nDate-$pCc+$pDd+31)%7;
41
        $pResult = 25-$pCc-$pEe;
42
        if ($pResult > 0) {
43
            $pEaster = strtotime($pYear.'/04/'.$pResult);
44
        } else {
45
            $pEaster = strtotime($pYear.'/03/'.(31+$pResult));
46
        }
47
        return $pEaster;
48
    }
49
50
    /**
51
     * get the next open day.
52
     *
53
     * @link http://codes-sources.commentcamarche.net/source/38705-jours-ouvres Jours ouvrés
54
     * @author Malalam
55
     *
56
     * @param timestamp $pDate Order date
57
     * @param integer   $pDays Delta for the day of delivery
58
     * @return integer  Delta next business day
59
     */
60
    public function getNextOpenDay($pDate, $pDays)
61
    {
62
        $aBankHolidays = ['1_1', '1_5', '8_5', '14_7', '15_8', '1_11', '11_11', '25_12', ];
63
        if (function_exists('easter_date')) {
64
            $pEaster = easter_date((int)date('Y'), $pDate);
65
        } else {
66
            $pEaster = $this->getEaster((int)date('Y'), $pDate);
0 ignored issues
show
Unused Code introduced by
The call to TimeHelper::getEaster() has too many arguments starting with $pDate.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
67
        }
68
        $aBankHolidays[] = date('j_n', $pEaster);
69
        $aBankHolidays[] = date('j_n', $pEaster + (86400*39));
70
        $aBankHolidays[] = date('j_n', $pEaster + (86400*49));
71
72
        $pEnd = $pDays * 86400;
73
        $idn = 0;
74
        while ($idn < $pEnd) {
75
            $idn = strtotime('+1 day', $idn);
76
            if (in_array(date('w', $pDate+$idn), array(0, 6)) || in_array(date('j_n', $pDate+$idn), $aBankHolidays)) {
77
                $pEnd = strtotime('+1 day', $pEnd);
78
                $pDays ++;
79
            }
80
        }
81
        return $pDays;
82
    }
83
}
84