Util::getMondayThisWeek()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\DateBundle;
11
12
class Util
13
{
14
    /**
15
     * Bugfix for get monday of this week.
16
     *
17
     * @see https://bugs.php.net/bug.php?id=63740
18
     *
19
     * @param \DateTime $date
20
     *
21
     * @return \DateTime
22
     */
23 9
    public static function getMondayThisWeek(\DateTime $date)
24
    {
25 9
        $monday = clone $date;
26 9
        $number = $monday->format('N');
27 9
        if ($number != 1) {
28 8
            $monday->modify('-'.($number - 1).' day');
29 8
        }
30
31 9
        return $monday;
32
    }
33
34
    /**
35
     * @deprecated it will be removed in later
36
     * @see RoundDate::round()
37
     * @codeCoverageIgnore
38
     *
39
     * @param \DateTime $date
40
     * @param int $seconds
41
     *
42
     * @return \DateTime
43
     */
44
    public static function roundDate(\DateTime $date, $seconds)
45
    {
46
        return RoundDate::round($date, $seconds);
47
    }
48
}
49