Passed
Push — master ( 6afdcd...dc022a )
by Hirofumi
05:03
created

NotificationDtoDataTransformer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 44
ccs 17
cts 20
cp 0.85
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A read() 0 25 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Application\DataTransformer;
5
6
use DateTime;
7
use Shippinno\Notification\Domain\Model\Notification;
8
9
class NotificationDtoDataTransformer implements NotificationDataTransformer
10
{
11
    /**
12
     * @var Notification
13
     */
14
    private $notification;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 2
    public function write(Notification $notification): void
20
    {
21 2
        $this->notification = $notification;
22 2
    }
23
24
    /**
25
     * @return array
26
     */
27 2
    public function read()
28
    {
29
        return [
30 2
            'id' => $this->notification->notificationId()->id(),
31 2
            'destination' => json_decode($this->notification->destination()->typedJsonRepresentation(), true),
32 2
            'subject' => $this->notification->subject()->subject(),
33 2
            'body' => $this->notification->body()->body(),
34 2
            'deduplication_key' => $this->notification->deduplicationKey()
35 1
                ? $this->notification->deduplicationKey()->key()
36
                : null,
37 2
            'metadata' => $this->notification->metadata(),
38 2
            'created_at' => $this->notification->createdAt()->format(DateTime::W3C),
39 2
            'failed_at' => $this->notification->failedAt()
40
                ? $this->notification->failedAt()->format(DateTime::W3C)
41
                : null,
42 2
            'failed_for' => $this->notification->failedFor(),
43 2
            'sent_at' => $this->notification->sentAt()
44
                ? $this->notification->sentAt()->format(DateTime::W3C)
45
                : null,
46 2
            'locked_at' => $this->notification->lockedAt()
47
                ? $this->notification->lockedAt()->format(DateTime::W3C)
48
                : null,
49 2
            'is_fresh' => $this->notification->isFresh(),
50
        ];
51
    }
52
}