Completed
Push — Order ( 5bfbdf...92abe2 )
by Laurent
03:29
created

TimeHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 61
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEaster() 0 19 3
B getNextOpenDay() 0 22 5
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
    function getNextOpenDay ($pDate, $pDays) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
	$aBankHolidays = ['1_1', '1_5', '8_5', '14_7', '15_8', '1_11', '11_11', '25_12', ];
62
	if (function_exists ('easter_date')) {
63
            $pEaster = easter_date ((int)date('Y'), $pDate);
64
	} else {
65
            $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...
66
	}
67
	$aBankHolidays[] = date ('j_n',$pEaster);
68
	$aBankHolidays[] = date ('j_n', $pEaster + (86400*39));
69
	$aBankHolidays[] = date ('j_n', $pEaster + (86400*49));
70
71
        $pEnd = $pDays * 86400;
72
	$idn = 0;
73
	while ($idn < $pEnd) {
74
		$idn = strtotime ('+1 day', $idn);
75
		if (in_array (date ('w', $pDate+$idn),array (0,6) ) || in_array (date ('j_n', $pDate+$idn), $aBankHolidays)) {
76
			$pEnd = strtotime ('+1 day', $pEnd);
77
			$pDays ++;
78
		}
79
	}
80
	return $pDays;
81
}
82
}
83