Skip to content

Commit

Permalink
PAYOSWXP-121: fixes phpstan and ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
amirinterlutions committed Mar 1, 2024
1 parent fbc5623 commit b81d409
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/Command/ResendNotifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

namespace PayonePayment\Command;

use PayonePayment\Components\ResendNotifyHandler\ResendNotifyHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PayonePayment\Components\ResendNotifyHandler\ResendNotifyHandler;

class ResendNotifyCommand extends Command
{
protected static $defaultName = 'payone:send-notify';

public function __construct(
private readonly ResendNotifyHandler $resendNotifyHandler
)
{
) {
parent::__construct();
}

Expand All @@ -23,7 +22,6 @@ protected function configure(): void
$this->setDescription('Send notification forwarding queue');
}


protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Sending notification forwarding queue');
Expand Down
12 changes: 7 additions & 5 deletions src/Components/ResendNotifyHandler/ResendNotifyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace PayonePayment\Components\ResendNotifyHandler;

use PayonePayment\DataAbstractionLayer\Entity\NotificationQueue\PayonePaymentNotificationQueueEntity;
use PayonePayment\Payone\Webhook\MessageBus\Command\NotificationForwardCommand;
use PayonePayment\Payone\Webhook\MessageBus\MessageHandler\NotificationForwardHandler;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
use PayonePayment\DataAbstractionLayer\Entity\NotificationQueue\PayonePaymentNotificationQueueEntity;
use PayonePayment\Payone\Webhook\MessageBus\MessageHandler\NotificationForwardHandler;

class ResendNotifyHandler
{
Expand All @@ -26,18 +26,20 @@ public function send(): void
$criteria = new Criteria();
$currentDate = new \DateTime();
$criteria->addFilter(new RangeFilter('nextExecutionTime', [
RangeFilter::LTE => $currentDate->format(Defaults::STORAGE_DATE_TIME_FORMAT)
RangeFilter::LTE => $currentDate->format(Defaults::STORAGE_DATE_TIME_FORMAT),
]));

$notificationQueue = $this->notificationQueueRepository->search($criteria, Context::createDefaultContext())->getEntities();

/** @var PayonePaymentNotificationQueueEntity $notification */
foreach ($notificationQueue as $notification) {
$messageDecode = base64_decode($notification->getMessage() ?: '', true);
/** @var NotificationForwardCommand $message */
$message = unserialize(base64_decode($notification->getMessage()),[]);
$message = unserialize($messageDecode, []);

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.4.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.5.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.0.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.3.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.4.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.0.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.6.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.6.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.3.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.5.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.1.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.1.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.2.0, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.7.3, PHP 8.1, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.2.0, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.7.3, PHP 8.1, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.2.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.1.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.0.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.6.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.0.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.2.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.4.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.3.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.5.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.1.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.4.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.3.0, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.7.3, PHP 8.2, MySQL 5.7

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.5.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.6.0, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

Check failure on line 38 in src/Components/ResendNotifyHandler/ResendNotifyHandler.php

View workflow job for this annotation

GitHub Actions / SW v6.5.7.3, PHP 8.2, MySQL 8.0

Parameter #1 $data of function unserialize expects string, string|false given.

$this->notificationForwardHandler->handle($message, true);
$this->notificationQueueRepository->delete([['id' => $notification->getId()]], Context::createDefaultContext());
}
echo "current time: " . $currentDate->format(Defaults::STORAGE_DATE_TIME_FORMAT) . "\n";
echo 'current time: ' . $currentDate->format(Defaults::STORAGE_DATE_TIME_FORMAT) . "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public function setMessage(?string $message): void
$this->message = $message;
}

public function getLastExecutionTime(): ?\DateTimeInterface
public function getLastExecutionTime(): \DateTimeInterface
{
return $this->lastExecutionTime;
}

public function setLastExecutionTime(?\DateTimeInterface $lastExecutionTime): void
public function setLastExecutionTime(\DateTimeInterface $lastExecutionTime): void
{
$this->lastExecutionTime = $lastExecutionTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PayonePaymentNotificationTargetEntity extends Entity
protected array $resendNotificationStatus;

protected ?string $username = null;

protected ?string $password = null;

public function getUrl(): string
Expand Down Expand Up @@ -90,6 +91,7 @@ public function setResendNotificationTime(array $resendNotificationTime): void
{
$this->resendNotificationTime = $resendNotificationTime;
}

public function getResendNotificationTime(): array
{
return $this->resendNotificationTime;
Expand All @@ -104,5 +106,4 @@ public function getResendNotificationStatus(): array
{
return $this->resendNotificationStatus;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

class NotificationForwardHandler implements MessageSubscriberInterface
{

public function __construct(
private readonly EntityRepository $notificationForwardRepository,
private readonly EntityRepository $notificationQueueRepository,
Expand Down Expand Up @@ -61,8 +60,11 @@ public function handle(NotificationForwardCommand $message, bool $isResendMessag
$responseInfo = curl_getinfo($handle);
$responseContent = curl_multi_getcontent($handle);
$this->statusLogger($responseInfo, $responseContent, $id);
if(!$isResendMessage) {
$this->createNotificationQueue($responseInfo, $message, $id, $notificationForwards->get($id));
if (!$isResendMessage) {
$notificationForward = $notificationForwards->get($id);
if ($notificationForward instanceof PayonePaymentNotificationForwardEntity) {
$this->createNotificationQueue($responseInfo, $message, $id, $notificationForward);
}
}

curl_multi_remove_handle($multiHandle, $handle);
Expand Down Expand Up @@ -135,6 +137,7 @@ private function getForwardRequests(\CurlMultiHandle $multiHandle, EntitySearchR

if (!\is_array($content)) {
$this->logger->error('Could not convert content to array', ['id' => $id]);

continue;
}

Expand Down Expand Up @@ -170,16 +173,17 @@ private function buildHeaders(
return $headers;
}

private function createNotificationQueue($responseInfo, $message, $notificationForwardId, $forwardRequest): void
private function createNotificationQueue(array $responseInfo, NotificationForwardCommand $message, string $notificationForwardId, PayonePaymentNotificationForwardEntity $notificationForward): void
{
$this->logger->info('Creating notification queue', ['id' => $notificationForwardId]);

$resendNotificationStatus = $forwardRequest->getNotificationTarget()?->getResendNotificationStatus();
if (!in_array($responseInfo['http_code'], $resendNotificationStatus, true)) {

$resendNotificationStatus = $notificationForward->getNotificationTarget()?->getResendNotificationStatus() ?? [];
if (!\in_array($responseInfo['http_code'], $resendNotificationStatus, true)) {
return;
}

$resendNotificationTime = $forwardRequest->getNotificationTarget()?->getResendNotificationTime();
$resendNotificationTime = $notificationForward->getNotificationTarget()?->getResendNotificationTime();

if ($resendNotificationTime === null) {
return;
Expand All @@ -188,6 +192,7 @@ private function createNotificationQueue($responseInfo, $message, $notificationF
foreach ($resendNotificationTime as $time) {
$nextExecutionTime = new \DateTime();
$nextExecutionTime->modify("+$time minutes");

try {
$this->notificationQueueRepository->create([
[
Expand All @@ -198,11 +203,11 @@ private function createNotificationQueue($responseInfo, $message, $notificationF
'nextExecutionTime' => $nextExecutionTime,
],
], $message->getContext());
}catch (\Exception $e) {
} catch (\Exception $e) {
$this->logger->error('Could not create notification queue', [
'notificationForwardId' => $notificationForwardId,
'nextExecutionTime' => $nextExecutionTime->format('Y-m-d H:i:s'),
'error' => $e->getMessage()
'error' => $e->getMessage(),
]);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/ScheduledTask/NotifySendRetryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class NotifySendRetryHandler extends ScheduledTaskHandler
{

public function __construct(
EntityRepository $scheduledTaskRepository,
private readonly ResendNotifyHandler $resendNotifyHandler
Expand Down

0 comments on commit b81d409

Please sign in to comment.