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

FetchNotificationHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Application\Query;
5
6
use Shippinno\Notification\Application\DataTransformer\NotificationDataTransformer;
7
use Shippinno\Notification\Domain\Model\NotificationId;
8
use Shippinno\Notification\Domain\Model\NotificationNotFoundException;
9
use Shippinno\Notification\Domain\Model\NotificationRepository;
10
11 View Code Duplication
class FetchNotificationHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var NotificationRepository
15
     */
16
    private $notificationRepository;
17
18
    /**
19
     * @var NotificationDataTransformer
20
     */
21
    private $notificationDataTransformer;
22
23
    /**
24
     * @param NotificationRepository $notificationRepository
25
     * @param NotificationDataTransformer $notificationDataTransformer
26
     */
27 2
    public function __construct(
28
        NotificationRepository $notificationRepository,
29
        NotificationDataTransformer $notificationDataTransformer
30
    ) {
31 2
        $this->notificationRepository = $notificationRepository;
32 2
        $this->notificationDataTransformer = $notificationDataTransformer;
33 2
    }
34
35
    /**
36
     * @param FetchNotification $query
37
     * @return mixed
38
     * @throws NotificationNotFoundException
39
     */
40 2
    public function handle(FetchNotification $query)
41
    {
42 2
        $notificationId = new NotificationId($query->notificationId());
43 2
        $notification = $this->notificationRepository->notificationOfId($notificationId);
44 2
        if (is_null($notification)) {
45 1
            throw new NotificationNotFoundException($notificationId);
46
        }
47 1
        $this->notificationDataTransformer->write($notification);
48
49 1
        return $this->notificationDataTransformer->read();
50
    }
51
}
52