Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 90 additions & 53 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,96 @@ parameters:
count: 1
path: ../Classes/Domain/Finisher/Form/AddToCartFinisherInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\DatabaseWriter\:\:jsonEncodeWithThrowable\(\) has parameter \$dataToEncode with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/DatabaseWriter.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:__construct\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:error\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:getArguments\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:info\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:notice\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\Log\:\:warning\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/Log.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:__construct\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:error\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:getArguments\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:info\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:notice\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Model\\LogInterface\:\:warning\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Model/LogInterface.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Repository\\LogRepository\:\:findAllByIdentifier\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Repository/LogRepository.php

-
message: '#^Method Extcode\\Cart\\Domain\\Log\\Repository\\LogRepository\:\:insert\(\) has parameter \$fieldValues with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../Classes/Domain/Log/Repository/LogRepository.php

-
message: '#^Method Extcode\\Cart\\Domain\\Model\\Cart\:\:getCart\(\) should return Extcode\\Cart\\Domain\\Model\\Cart\\Cart\|null but returns mixed\.$#'
identifier: return.type
Expand Down Expand Up @@ -5472,56 +5562,3 @@ parameters:
count: 1
path: ../ext_emconf.php

-
message: '#^Cannot access an offset on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''1588829280'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''MAIL'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''SYS'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''cart'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''fluid'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''namespaces'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''partialRootPaths'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php

-
message: '#^Cannot access offset ''templateRootPaths'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: ../ext_localconf.php
27 changes: 26 additions & 1 deletion Classes/Controller/Backend/Order/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,35 @@
*/

use Extcode\Cart\Controller\Backend\ActionController;
use Extcode\Cart\Domain\Log\LogServiceInterface;
use Extcode\Cart\Domain\Log\Model\Log;
use Extcode\Cart\Domain\Model\Order\Payment;
use Extcode\Cart\Domain\Repository\Order\PaymentRepository;
use Extcode\Cart\Event\Order\UpdateServiceEvent;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

class PaymentController extends ActionController
{
public function __construct(
protected PaymentRepository $paymentRepository
private readonly PaymentRepository $paymentRepository,
private readonly LogServiceInterface $logService,
) {}

public function updateAction(Payment $payment): ResponseInterface
{
$this->paymentRepository->update($payment);
$this->logService->write(
Log::info(
$this->getOrderItemUid($payment),
'updatePayment',
'Payment was set to ' . $payment->getStatus() . '.',
[
'time' => time(),
]
)
);

$event = new UpdateServiceEvent($payment);
$this->eventDispatcher->dispatch($event);
Expand All @@ -40,4 +54,15 @@ public function updateAction(Payment $payment): ResponseInterface

return $this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $payment->getItem()]);
}

private function getOrderItemUid(Payment $payment): int
{
$orderItemUid = $payment->getItem()?->getUid();

if (is_null($orderItemUid)) {
throw new InvalidArgumentException('Method should only called for persisted orders.', 1774715307);
}

return $orderItemUid;
}
}
27 changes: 26 additions & 1 deletion Classes/Controller/Backend/Order/ShippingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,35 @@
*/

use Extcode\Cart\Controller\Backend\ActionController;
use Extcode\Cart\Domain\Log\LogServiceInterface;
use Extcode\Cart\Domain\Log\Model\Log;
use Extcode\Cart\Domain\Model\Order\Shipping;
use Extcode\Cart\Domain\Repository\Order\ShippingRepository;
use Extcode\Cart\Event\Order\UpdateServiceEvent;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

class ShippingController extends ActionController
{
public function __construct(
protected ShippingRepository $shippingRepository
private readonly ShippingRepository $shippingRepository,
private readonly LogServiceInterface $logService,
) {}

public function updateAction(Shipping $shipping): ResponseInterface
{
$this->shippingRepository->update($shipping);
$this->logService->write(
Log::info(
$this->getOrderItemUid($shipping),
'updateShipping',
'Shipping was set to ' . $shipping->getStatus() . '.',
[
'time' => time(),
]
)
);

$event = new UpdateServiceEvent($shipping);
$this->eventDispatcher->dispatch($event);
Expand All @@ -40,4 +54,15 @@ public function updateAction(Shipping $shipping): ResponseInterface

return $this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $shipping->getItem()]);
}

private function getOrderItemUid(Shipping $shipping): int
{
$orderItemUid = $shipping->getItem()?->getUid();

if (is_null($orderItemUid)) {
throw new InvalidArgumentException('Method should only called for persisted orders.', 1774715307);
}

return $orderItemUid;
}
}
58 changes: 58 additions & 0 deletions Classes/Domain/Log/DatabaseWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Log;

use Extcode\Cart\Domain\Log\Model\LogInterface;
use Extcode\Cart\Domain\Log\Repository\LogRepository;
use Throwable;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Log\Writer\AbstractWriter;
use TYPO3\CMS\Core\Log\Writer\WriterInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final class DatabaseWriter extends AbstractWriter
{
public function writeLog(LogRecord $record): WriterInterface
{
$recordData = $record->getData();

$log = $recordData['log'] ?? null;
if (($log instanceof LogInterface) === false) {
return $this;
}
unset($recordData['log']);

$fieldValues = [
'log_level' => $log->getLogLevel()->value,
'item' => $log->getOrderItemId(),
'type' => $log->getType(),
'message' => $log->getMessage(),
'arguments' => $this->jsonEncodeWithThrowable($log->getArguments()),
'request_id' => $record->getRequestId(),
'time_micro' => $record->getCreated(),
'level' => $record->getLevel(),
'data' => $this->jsonEncodeWithThrowable($recordData),
];

$logRepository = GeneralUtility::makeInstance(LogRepository::class);
$logRepository->insert($fieldValues);

return $this;
}

public function jsonEncodeWithThrowable(array $dataToEncode): string
{
$data = '';
if (!empty($dataToEncode)) {
// Fold an exception into the message, and string-ify it into recordData so it can be jsonified.
if (isset($dataToEncode['exception']) && $dataToEncode['exception'] instanceof Throwable) {
$dataToEncode['exception'] = (string)$dataToEncode['exception'];
}
$data = '- ' . json_encode($dataToEncode);
}

return $data;
}
}
27 changes: 27 additions & 0 deletions Classes/Domain/Log/LogService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Log;

use Extcode\Cart\Domain\Log\Model\LogInterface;
use Psr\Log\LoggerInterface;

final readonly class LogService implements LogServiceInterface
{
public function __construct(
private LoggerInterface $logger,
) {}

public function write(
LogInterface $log
): void {
$this->logger->log(
$log->getLogLevel()->value,
$log->getMessage(),
[
'log' => $log,
]
);
}
}
12 changes: 12 additions & 0 deletions Classes/Domain/Log/LogServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Extcode\Cart\Domain\Log;

use Extcode\Cart\Domain\Log\Model\LogInterface;

interface LogServiceInterface
{
public function write(LogInterface $log): void;
}
Loading
Loading