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

FetchNotificationHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 41
loc 41
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A handle() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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