Completed
Pull Request — master (#338)
by Luc
05:44
created

RecordedOn::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
use Broadway\Domain\DomainMessage;
6
use Broadway\Domain\DateTime;
7
8
class RecordedOn
9
{
10
    /**
11
     * @var DateTime
12
     */
13
    private $recorded;
14
15
    /**
16
     * ModifiedDateTime constructor.
17
     * @param DateTime $recorded
18
     */
19
    private function __construct(DateTime $recorded)
20
    {
21
        $this->recorded = $recorded;
22
    }
23
24
    /**
25
     * @param DomainMessage $domainMessage
26
     * @return RecordedOn
27
     */
28
    public static function fromDomainMessage(DomainMessage $domainMessage)
29
    {
30
        return new self($domainMessage->getRecordedOn());
31
    }
32
33
    /**
34
     * @param DateTime $dateTime
35
     * @return RecordedOn
36
     */
37
    public static function fromBroadwayDateTime(DateTime $dateTime)
38
    {
39
        return new self($dateTime);
40
    }
41
42
    /**
43
     * @return DateTime
44
     */
45
    public function toBroadwayDateTime()
46
    {
47
        return $this->recorded;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function toString()
54
    {
55
        return \DateTime::createFromFormat(
56
            DateTime::FORMAT_STRING,
57
            $this->recorded->toString()
58
        )->format('c');
59
    }
60
}
61