Skip to content

Commit

Permalink
sugar syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Jun 27, 2024
1 parent c64cd7b commit 9350f2f
Show file tree
Hide file tree
Showing 39 changed files with 68 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@

class OptionSourceSelect extends Select
{
/**
* @var OptionSourceInterface
*/
private OptionSourceInterface $optionSource;

public function __construct(
Context $context,
OptionSourceInterface $optionSource,
private OptionSourceInterface $optionSource,
array $data = []
) {
$this->optionSource = $optionSource;
parent::__construct($context, $data);
}

Expand Down
10 changes: 2 additions & 8 deletions Block/Adminhtml/Customer/Edit/EraseButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@

class EraseButton extends GenericButton implements ButtonProviderInterface
{
private EraseEntityCheckerInterface $eraseCustomerChecker;

private Config $config;

public function __construct(
Context $context,
Registry $registry,
EraseEntityCheckerInterface $eraseCustomerChecker,
Config $config
private EraseEntityCheckerInterface $eraseCustomerChecker,
private Config $config
) {
$this->eraseCustomerChecker = $eraseCustomerChecker;
$this->config = $config;
parent::__construct($context, $registry);
}

Expand Down
5 changes: 1 addition & 4 deletions Block/Adminhtml/Customer/Edit/ExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

class ExportButton extends GenericButton implements ButtonProviderInterface
{
private Config $config;

public function __construct(
Context $context,
Registry $registry,
Config $config
private Config $config
) {
$this->config = $config;
parent::__construct($context, $registry);
}

Expand Down
7 changes: 2 additions & 5 deletions Block/Adminhtml/Order/Edit/EraseButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

class EraseButton extends AbstractBlock
{
private EraseEntityCheckerInterface $eraseEntityChecker;

public function __construct(
Context $context,
EraseEntityCheckerInterface $eraseEntityChecker,
private EraseEntityCheckerInterface $eraseEntityChecker,
array $data = []
) {
$this->eraseEntityChecker = $eraseEntityChecker;
parent::__construct($context, $data);
}

Expand All @@ -37,7 +34,7 @@ protected function _construct(): void

/** @var View $orderView */
$orderView = $this->getLayout()->getBlock('sales_order_edit');
$orderId = (int) $orderView->getOrderId();
$orderId = (int)$orderView->getOrderId();

if ($this->_authorization->isAllowed('Opengento_Gdpr::order_erase') &&
$this->eraseEntityChecker->canCreate($orderId, 'order')
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Order/Edit/ExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function _construct(): void

/** @var View $orderView */
$orderView = $this->getLayout()->getBlock('sales_order_edit');
$orderId = (int) $orderView->getOrderId();
$orderId = (int)$orderView->getOrderId();

if ($this->_authorization->isAllowed('Opengento_Gdpr::order_export')) {
$orderView->addButton(
Expand Down
2 changes: 1 addition & 1 deletion Controller/Privacy/Erase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function isAllowed(): bool

protected function executeAction(): Page|Redirect
{
if ($this->eraseCustomerChecker->exists((int) $this->customerSession->getCustomerId(), 'customer')) {
if ($this->eraseCustomerChecker->exists((int)$this->customerSession->getCustomerId(), 'customer')) {
$this->messageManager->addErrorMessage(new Phrase('Your account is already being removed.'));
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
Expand Down
2 changes: 1 addition & 1 deletion Cron/EraseEntityScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ private function scheduleEntitiesErasure(): void

private function resolveErasureMaxAge(): int
{
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE);
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE);
}
}
2 changes: 1 addition & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function isErasureEnabled(): bool
*/
public function getAllowedStatesToErase(): array
{
return explode(',', (string) $this->scopeConfig->getValue(
return explode(',', (string)$this->scopeConfig->getValue(
self::CONFIG_PATH_ERASURE_ALLOWED_STATES,
ScopeInterface::SCOPE_STORE
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function anonymizeCustomer(CustomerInterface $customer): void
$secureData = $this->customerRegistry->retrieveSecureData($customer->getId());
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
$secureData->setPasswordHash(sha1(uniqid((string) mt_rand(), true)));
$secureData->setPasswordHash(sha1(uniqid((string)mt_rand(), true)));

$customer = $this->anonymizer->anonymize($customer);
if ($customer instanceof DataObject) {
Expand Down
2 changes: 1 addition & 1 deletion Model/Customer/Anonymize/Processor/OrderDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function execute(int $customerId): bool
foreach ($orderList->getItems() as $order) {
$lastActive = new DateTime($order->getUpdatedAt());
$this->salesInformation->isAlive($lastActive)
? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive)
? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive)
: $this->anonymize($order);
}

Expand Down
38 changes: 8 additions & 30 deletions Model/Customer/CustomerChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,24 @@

namespace Opengento\Gdpr\Model\Customer;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Opengento\Gdpr\Model\Config;
use Opengento\Gdpr\Model\Entity\EntityCheckerInterface;

class CustomerChecker implements EntityCheckerInterface
{
private OrderRepositoryInterface $orderRepository;

private SearchCriteriaBuilder $criteriaBuilder;

private Config $config;

/**
* @var bool[]
*/
private array $cache;

public function __construct(
OrderRepositoryInterface $orderRepository,
SearchCriteriaBuilder $criteriaBuilder,
Config $config
) {
$this->orderRepository = $orderRepository;
$this->criteriaBuilder = $criteriaBuilder;
$this->config = $config;
$this->cache = [];
}
private CollectionFactory $collectionFactory,
private Config $config
) {}

public function canErase(int $customerId): bool
{
if (!isset($this->cache[$customerId])) {
$this->criteriaBuilder->addFilter(OrderInterface::STATE, $this->config->getAllowedStatesToErase(), 'nin');
$this->criteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
$orderList = $this->orderRepository->getList($this->criteriaBuilder->create());

$this->cache[$customerId] = !$orderList->getTotalCount();
}
$collection = $this->collectionFactory->create();
$collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $customerId);
$collection->addFieldToFilter(OrderInterface::STATE, ['nin' => $this->config->getAllowedStatesToErase()]);

return $this->cache[$customerId];
return $collection->getSize() > 0;

This comment has been minimized.

Copy link
@kpitn

kpitn Aug 20, 2024

you inverse the count detection

}
}
2 changes: 1 addition & 1 deletion Model/Customer/Delete/Processor/OrderDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function execute(int $customerId): bool
foreach ($orderList->getItems() as $order) {
$lastActive = new DateTime($order->getUpdatedAt());
$this->salesInformation->isAlive($lastActive)
? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive)
? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive)
: $this->orderRepository->delete($order);
}

Expand Down
2 changes: 1 addition & 1 deletion Model/Customer/Notifier/MailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function send(CustomerInterface $customer): void
{
$storeId = $customer->getStoreId() === null ? null : (int) $customer->getStoreId();
$storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId();
$vars = [
'customer' => $customer,
'store' => $this->storeManager->getStore($customer->getStoreId()),
Expand Down
2 changes: 1 addition & 1 deletion Model/Customer/OrigDataRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public function get(int $customerId): ?CustomerInterface

public function set(CustomerInterface $customer): void
{
$this->customers[(int) $customer->getId()] = $customer;
$this->customers[(int)$customer->getId()] = $customer;
}
}
2 changes: 1 addition & 1 deletion Model/Erase/EraseEntityScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function schedule(array $entityTypes, Filter $filter): void
*/
foreach ($this->collectEntityIds($entityTypes, $filter) as $entityType => $entityIds) {
foreach ($entityIds as $entityId) {
$this->eraseManagement->create((int) $entityId, $entityType);
$this->eraseManagement->create((int)$entityId, $entityType);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Erase/EraseSalesInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function isAlive(DateTimeInterface $lastActive): bool

private function resolveErasureSalesMaxAge(): int
{
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE, ScopeInterface::SCOPE_STORE);
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE, ScopeInterface::SCOPE_STORE);
}
}
16 changes: 8 additions & 8 deletions Model/EraseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function _construct(): void

public function getEraseId(): int
{
return (int) $this->getId();
return (int)$this->getId();
}

public function setEraseId(int $eraseId): EraseEntityInterface
Expand All @@ -32,7 +32,7 @@ public function setEraseId(int $eraseId): EraseEntityInterface

public function getEntityId(): int
{
return (int) $this->_getData(self::ENTITY_ID);
return (int)$this->_getData(self::ENTITY_ID);
}

public function setEntityId($entityId): EraseEntityInterface
Expand All @@ -42,7 +42,7 @@ public function setEntityId($entityId): EraseEntityInterface

public function getEntityType(): string
{
return (string) $this->_getData(self::ENTITY_TYPE);
return (string)$this->_getData(self::ENTITY_TYPE);
}

public function setEntityType(string $entityType): EraseEntityInterface
Expand All @@ -52,7 +52,7 @@ public function setEntityType(string $entityType): EraseEntityInterface

public function getScheduledAt(): string
{
return (string) $this->_getData(self::SCHEDULED_AT);
return (string)$this->_getData(self::SCHEDULED_AT);
}

public function setScheduledAt(string $scheduledAt): EraseEntityInterface
Expand All @@ -62,7 +62,7 @@ public function setScheduledAt(string $scheduledAt): EraseEntityInterface

public function getState(): string
{
return (string) $this->_getData(self::STATE);
return (string)$this->_getData(self::STATE);
}

public function setState(string $state): EraseEntityInterface
Expand All @@ -72,7 +72,7 @@ public function setState(string $state): EraseEntityInterface

public function getStatus(): string
{
return (string) $this->_getData(self::STATUS);
return (string)$this->_getData(self::STATUS);
}

public function setStatus(string $status): EraseEntityInterface
Expand All @@ -82,7 +82,7 @@ public function setStatus(string $status): EraseEntityInterface

public function getMessage(): ?string
{
return $this->_getData(self::MESSAGE) === null ? null : (string) $this->_getData(self::MESSAGE);
return $this->_getData(self::MESSAGE) === null ? null : (string)$this->_getData(self::MESSAGE);
}

public function setMessage(?string $message): EraseEntityInterface
Expand All @@ -92,7 +92,7 @@ public function setMessage(?string $message): EraseEntityInterface

public function getErasedAt(): string
{
return (string) $this->_getData(self::ERASED_AT);
return (string)$this->_getData(self::ERASED_AT);
}

public function setErasedAt(string $erasedAt): EraseEntityInterface
Expand Down
2 changes: 1 addition & 1 deletion Model/EraseEntityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public function exists(int $entityId, string $entityType): bool
{
try {
return (bool) $this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId();
return (bool)$this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId();
} catch (NoSuchEntityException $e) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/EraseEntityManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ private function retrieveScheduledAt(): string

private function resolveErasureDelay(): int
{
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
}
}
2 changes: 1 addition & 1 deletion Model/Export/ExportToFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function export(ExportEntityInterface $exportEntity): string

public function resolveExportRendererCodes(): array
{
return explode(',', (string) $this->scopeConfig->getValue(
return explode(',', (string)$this->scopeConfig->getValue(
self::CONFIG_PATH_EXPORT_RENDERERS,
ScopeInterface::SCOPE_STORE
));
Expand Down
Loading

0 comments on commit 9350f2f

Please sign in to comment.