WeekDay   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 46
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A now() 0 6 1
A fromNativeDateTime() 0 6 1
A getNumericValue() 0 4 1
1
<?php
2
3
namespace ValueObjects\DateTime;
4
5
use ValueObjects\Enum\Enum;
6
7
class WeekDay extends Enum
8
{
9
    const MONDAY    = 'Monday';
10
    const TUESDAY   = 'Tuesday';
11
    const WEDNESDAY = 'Wednesday';
12
    const THURSDAY  = 'Thursday';
13
    const FRIDAY    = 'Friday';
14
    const SATURDAY  = 'Saturday';
15
    const SUNDAY    = 'Sunday';
16
17
    /**
18
     * Returns the current week day.
19
     *
20
     * @return WeekDay
21
     */
22 1
    public static function now()
23
    {
24 1
        $now = new \DateTime('now');
25
26 1
        return static::fromNativeDateTime($now);
27
    }
28
29
    /**
30
     * Returns a WeekDay from a PHP native \DateTime
31
     *
32
     * @param  \DateTime $date
33
     * @return WeekDay
34
     */
35 2
    public static function fromNativeDateTime(\DateTime $date)
36
    {
37 2
        $weekDay = \strtoupper($date->format('l'));
38
39 2
        return static::getByName($weekDay);
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\Enum::getByName() has been deprecated.

This method has been deprecated.

Loading history...
40
    }
41
42
    /**
43
     * Returns a numeric representation of the WeekDay.
44
     * 1 for Monday to 7 for Sunday.
45
     *
46
     * @return int
47
     */
48 1
    public function getNumericValue()
49
    {
50 1
        return $this->getOrdinal() + 1;
51
    }
52
}
53