Skip to content

Commit 57fcad2

Browse files
committed
TASK: code style improvements
1 parent 5203017 commit 57fcad2

16 files changed

+102
-147
lines changed

Classes/Aop/LoggingAspect.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php
2+
23
namespace Swisscom\CommunicationDispatcher\Aop;
34

45
/*
56
* This file is part of the Swisscom.CommunicationDispatcher package.
67
*/
78

8-
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
99
use Neos\Flow\Annotations as Flow;
1010
use Neos\Flow\Aop\JoinPointInterface;
11+
use Neos\Flow\Log\ThrowableStorageInterface;
12+
use Psr\Log\LoggerInterface;
13+
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
1114

1215
/**
1316
* @Flow\Scope("singleton")
@@ -18,18 +21,19 @@ class LoggingAspect
1821

1922
/**
2023
* @Flow\Inject
21-
* @var \Psr\Log\LoggerInterface
24+
* @var LoggerInterface
2225
*/
2326
protected $logger;
2427

2528
/**
26-
* @var \Neos\Flow\Log\ThrowableStorageInterface
29+
* @var ThrowableStorageInterface
2730
* @Flow\Inject
2831
*/
2932
protected $throwableStorage;
3033

3134
/**
3235
* Logs dispatcher calls
36+
*
3337
* @Flow\After("within(Swisscom\CommunicationDispatcher\Channel\ChannelInterface) && method(.*->send())")
3438
* @param JoinPointInterface $joinPoint The current joinpoint
3539
* @return void

Classes/Channel/ChannelInterface.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
*/
88

99
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
10-
use Neos\Flow\Annotations as Flow;
1110

12-
/**
13-
* Channel interface
14-
*/
1511
interface ChannelInterface
1612
{
1713

@@ -22,5 +18,5 @@ interface ChannelInterface
2218
* @param array $options
2319
* @return void
2420
*/
25-
public function send(Recipient $recipient, $subject, $text, $options = array());
21+
public function send(Recipient $recipient, string $subject, string $text, array $options = []);
2622
}

Classes/Channel/EmailChannel.php

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
<?php
2+
23
namespace Swisscom\CommunicationDispatcher\Channel;
34

45
/*
56
* This file is part of the Swisscom.CommunicationDispatcher package.
67
*/
78

9+
use Neos\Flow\Annotations as Flow;
810
use Neos\Flow\ResourceManagement\PersistentResource;
11+
use Neos\Flow\ResourceManagement\ResourceManager;
912
use Neos\SwiftMailer\Message;
13+
use Swift_Attachment;
14+
use Swift_Image;
15+
use Swift_Message;
1016
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
11-
use Swisscom\CommunicationDispatcher\Domain\Repository\AssetRepository;
12-
use Neos\Flow\Annotations as Flow;
13-
use Neos\Flow\ResourceManagement\ResourceManager;
1417
use Swisscom\CommunicationDispatcher\Exception;
1518

1619
/**
1720
* @Flow\Scope("prototype")
1821
*/
1922
class EmailChannel implements ChannelInterface
2023
{
21-
/**
22-
* @Flow\Inject
23-
* @var AssetRepository
24-
*/
25-
protected $assetRepository;
2624

2725
/**
2826
* @Flow\Inject
@@ -63,7 +61,7 @@ function __construct(array $options = [])
6361
* @return void
6462
* @throws Exception
6563
*/
66-
public function send(Recipient $recipient, $subject, $text, $options = array())
64+
public function send(Recipient $recipient, string $subject, string $text, array $options = [])
6765
{
6866
$toEmail = $recipient->getEmail();
6967
$toName = $recipient->getName();
@@ -87,11 +85,11 @@ public function send(Recipient $recipient, $subject, $text, $options = array())
8785
$mail->setBody($text, 'text/html', 'utf-8');
8886
$mail->addPart($plaintext, 'text/plain', 'utf-8');
8987
foreach ($attachedResources as $resource) {
90-
if ($resource instanceof \Neos\Flow\ResourceManagement\PersistentResource) {
88+
if ($resource instanceof PersistentResource) {
9189
if ($swiftAttachment = $this->createSwiftAttachmentFromPersistentResource($resource)) {
9290
$mail->attach($swiftAttachment);
9391
}
94-
} elseif ($resource instanceof \Swift_Attachment) {
92+
} elseif ($resource instanceof Swift_Attachment) {
9593
$mail->attach($resource);
9694
}
9795
}
@@ -102,30 +100,15 @@ public function send(Recipient $recipient, $subject, $text, $options = array())
102100
}
103101
}
104102

105-
/**
106-
* @param PersistentResource $resource
107-
* @return \Swift_Attachment
108-
*/
109-
public function createSwiftAttachmentFromPersistentResource(PersistentResource $resource)
110-
{
111-
// No exception handling here. This provides flexibility to handle it outside or by aspects
112-
$path = $resource->createTemporaryLocalCopy();
113-
$attachment = \Swift_Attachment::fromPath($path, $resource->getMediaType());
114-
$attachment->setFilename($resource->getFilename());
115-
116-
return $attachment;
117-
}
118-
119103
/**
120104
* Embed images. I.e:
121105
* <img height="40px" src="###IMAGE:'{template.logo}'###" alt="Logo"/>
122106
*
123-
* @param $html
124-
* @param \Swift_Message $mail
125-
*
107+
* @param string $html
108+
* @param Swift_Message $mail
126109
* @return string $html
127110
*/
128-
private function embedResources($html, &$mail)
111+
private function embedResources(string $html, Swift_Message &$mail): string
129112
{
130113
$html = preg_replace_callback('/###IMAGE:(.+?)###/', function ($matches) use ($mail) {
131114
return $this->embedImageResourceCallback($matches, $mail);
@@ -139,17 +122,16 @@ private function embedResources($html, &$mail)
139122

140123
/**
141124
* @param array $matches
142-
* @param \Swift_Message $mail $mail
143-
*
125+
* @param \Swift_Message $mail
144126
* @return string
145127
*/
146-
private function embedImageResourceCallback($matches, &$mail)
128+
private function embedImageResourceCallback(array $matches, Swift_Message &$mail): string
147129
{
148130
$cid = '';
149131
if (isset($matches[1])) {
150132
$source = trim($matches[1], '\'');
151133
try {
152-
$cid = $mail->embed(\Swift_Image::fromPath($source));
134+
$cid = $mail->embed(Swift_Image::fromPath($source));
153135
} catch (\Exception $e) {
154136
// Nothing to do here
155137
}
@@ -159,10 +141,9 @@ private function embedImageResourceCallback($matches, &$mail)
159141

160142
/**
161143
* @param array $matches
162-
*
163144
* @return string
164145
*/
165-
private function embedPlainResourceCallback($matches)
146+
private function embedPlainResourceCallback(array $matches): string
166147
{
167148
$plain = '';
168149
if (isset($matches[1])) {
@@ -175,4 +156,18 @@ private function embedPlainResourceCallback($matches)
175156
}
176157
return $plain;
177158
}
159+
160+
/**
161+
* @param PersistentResource $resource
162+
* @return Swift_Attachment
163+
*/
164+
public function createSwiftAttachmentFromPersistentResource(PersistentResource $resource): Swift_Attachment
165+
{
166+
// No exception handling here. This provides flexibility to handle it outside or by aspects
167+
$path = $resource->createTemporaryLocalCopy();
168+
$attachment = Swift_Attachment::fromPath($path, $resource->getMediaType());
169+
$attachment->setFilename($resource->getFilename());
170+
171+
return $attachment;
172+
}
178173
}

Classes/Channel/NotificationChannel.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
2+
23
namespace Swisscom\CommunicationDispatcher\Channel;
34

45
/*
56
* This file is part of the Swisscom.CommunicationDispatcher package.
67
*/
78

9+
use Neos\Flow\Annotations as Flow;
10+
use Neos\Party\Domain\Model\Person;
811
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
912
use Swisscom\CommunicationDispatcher\Domain\Model\Notification;
1013
use Swisscom\CommunicationDispatcher\Domain\Repository\NotificationRepository;
1114
use Swisscom\CommunicationDispatcher\Exception;
12-
use Neos\Flow\Annotations as Flow;
13-
use Neos\Party\Domain\Model\Person;
1415

1516
class NotificationChannel implements ChannelInterface
1617
{
@@ -28,7 +29,7 @@ class NotificationChannel implements ChannelInterface
2829
* @param array $options
2930
* @throws Exception
3031
*/
31-
public function send(Recipient $recipient, $subject, $text, $options = array())
32+
public function send(Recipient $recipient, string $subject, string $text, array $options = [])
3233
{
3334
if ($recipient->getPerson() instanceof Person) {
3435
$newNotification = $this->createNotification($recipient, $subject, $text);
@@ -44,10 +45,8 @@ public function send(Recipient $recipient, $subject, $text, $options = array())
4445
* @param string $text
4546
* @return Notification
4647
*/
47-
protected function createNotification(Recipient $recipient, $subject, $text)
48+
protected function createNotification(Recipient $recipient, string $subject, string $text)
4849
{
49-
$newNotification = new Notification($recipient->getPerson(), $subject, $text);
50-
51-
return $newNotification;
50+
return new Notification($recipient->getPerson(), $subject, $text);
5251
}
5352
}

Classes/Channel/VoidChannel.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Swisscom\CommunicationDispatcher\Channel;
34

45
/*
@@ -7,12 +8,7 @@
78

89
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
910
use Swisscom\CommunicationDispatcher\Exception;
10-
use Neos\Flow\Annotations as Flow;
1111

12-
/**
13-
* Class VoidChannel for testing purpose
14-
* @package Swisscom\CommunicationDispatcher\Channel
15-
*/
1612
class VoidChannel implements ChannelInterface
1713
{
1814

@@ -23,7 +19,7 @@ class VoidChannel implements ChannelInterface
2319
* @param array $options
2420
* @throws Exception
2521
*/
26-
public function send(Recipient $recipient, $subject, $text, $options = array())
22+
public function send(Recipient $recipient, string $subject, string $text, array $options = [])
2723
{
2824
}
2925
}

Classes/Dispatcher/Dispatcher.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* This file is part of the Swisscom.CommunicationDispatcher package.
77
*/
88

9+
use Neos\Flow\Annotations as Flow;
910
use Swisscom\CommunicationDispatcher\Channel\ChannelInterface;
1011
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
11-
use Neos\Flow\Annotations as Flow;
12+
use Swisscom\CommunicationDispatcher\Service\MessageService;
1213

1314
class Dispatcher implements DispatcherInterface
1415
{
@@ -19,7 +20,7 @@ class Dispatcher implements DispatcherInterface
1920
protected $channelInterface;
2021

2122
/**
22-
* @var \Swisscom\CommunicationDispatcher\Service\MessageService
23+
* @var MessageService
2324
* @Flow\Inject
2425
*/
2526
protected $messageService;
@@ -28,7 +29,7 @@ class Dispatcher implements DispatcherInterface
2829
* @param ChannelInterface $channelInterface
2930
* @return void
3031
*/
31-
public function setChannelInterface(ChannelInterface $channelInterface = null)
32+
public function setChannelInterface(ChannelInterface $channelInterface)
3233
{
3334
$this->channelInterface = $channelInterface;
3435
}
@@ -41,7 +42,7 @@ public function setChannelInterface(ChannelInterface $channelInterface = null)
4142
* @param array $options
4243
* @return void
4344
*/
44-
public function dispatch(Recipient $recipient, $subject, $text, $params = array(), $options = array())
45+
public function dispatch(Recipient $recipient, string $subject, string $text, array $params = [], array $options = [])
4546
{
4647
$renderedSubject = $this->messageService->renderSubject($subject, $params);
4748
$renderedText = $this->messageService->renderText($text, $params);

Classes/Dispatcher/DispatcherFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* This file is part of the Swisscom.CommunicationDispatcher package.
66
*/
77

8-
use Swisscom\CommunicationDispatcher\Channel\ChannelInterface;
98
use Neos\Flow\Annotations as Flow;
9+
use Swisscom\CommunicationDispatcher\Channel\ChannelInterface;
1010

1111
/**
1212
* The factory used to create communication channel instances.
@@ -27,7 +27,7 @@ class DispatcherFactory
2727
* @param array $channelOptions
2828
* @return DispatcherInterface
2929
*/
30-
public function create($identifier, array $channelOptions = [])
30+
public function create(string $identifier, array $channelOptions = []): DispatcherInterface
3131
{
3232
$configuration = $this->dispatcherConfigurations[$identifier];
3333
$objectName = $configuration['objectName'];

Classes/Dispatcher/DispatcherInterface.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
use Swisscom\CommunicationDispatcher\Channel\ChannelInterface;
1010
use Swisscom\CommunicationDispatcher\Domain\Model\Dto\Recipient;
11-
use Neos\Flow\Annotations as Flow;
1211

13-
/**
14-
* Marker interface
15-
*/
1612
interface DispatcherInterface
1713
{
1814

@@ -30,5 +26,5 @@ public function setChannelInterface(ChannelInterface $channelInterface);
3026
* @param array $options
3127
* @return void
3228
*/
33-
public function dispatch(Recipient $recipient, $subject, $text, $params = array(), $options = array());
29+
public function dispatch(Recipient $recipient, string $subject, string $text, array $params = [], array $options = []);
3430
}

Classes/Domain/Model/Dto/Recipient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Swisscom\CommunicationDispatcher\Domain\Model\Dto;
34

45
/*
@@ -30,12 +31,11 @@ class Recipient
3031
protected $name = '';
3132

3233
/**
33-
* Recipient constructor.
3434
* @param Person|null $person
3535
* @param string $email
3636
* @param string $name
3737
*/
38-
public function __construct(Person $person = null, $email = '', $name = '')
38+
public function __construct(?Person $person = null, string $email = '', string $name = '')
3939
{
4040
if ($person instanceof Person) {
4141
$this->person = $person;
@@ -53,17 +53,17 @@ public function __construct(Person $person = null, $email = '', $name = '')
5353
}
5454

5555
/**
56-
* @return Person
56+
* @return Person|null
5757
*/
58-
public function getPerson()
58+
public function getPerson(): ?Person
5959
{
6060
return $this->person;
6161
}
6262

6363
/**
64-
* @param Person $person
64+
* @param Person|null $person
6565
*/
66-
public function setPerson($person)
66+
public function setPerson(?Person $person)
6767
{
6868
$this->person = $person;
6969
}

0 commit comments

Comments
 (0)