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 |
|
|
|
|
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
|
|
|
|
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.