Skip to content

Commit 9350f2f

Browse files
committed
sugar syntax
1 parent c64cd7b commit 9350f2f

39 files changed

+68
-115
lines changed

Block/Adminhtml/Config/Form/Field/Select/OptionSourceSelect.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@
1313

1414
class OptionSourceSelect extends Select
1515
{
16-
/**
17-
* @var OptionSourceInterface
18-
*/
19-
private OptionSourceInterface $optionSource;
20-
2116
public function __construct(
2217
Context $context,
23-
OptionSourceInterface $optionSource,
18+
private OptionSourceInterface $optionSource,
2419
array $data = []
2520
) {
26-
$this->optionSource = $optionSource;
2721
parent::__construct($context, $data);
2822
}
2923

Block/Adminhtml/Customer/Edit/EraseButton.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@
1717

1818
class EraseButton extends GenericButton implements ButtonProviderInterface
1919
{
20-
private EraseEntityCheckerInterface $eraseCustomerChecker;
21-
22-
private Config $config;
23-
2420
public function __construct(
2521
Context $context,
2622
Registry $registry,
27-
EraseEntityCheckerInterface $eraseCustomerChecker,
28-
Config $config
23+
private EraseEntityCheckerInterface $eraseCustomerChecker,
24+
private Config $config
2925
) {
30-
$this->eraseCustomerChecker = $eraseCustomerChecker;
31-
$this->config = $config;
3226
parent::__construct($context, $registry);
3327
}
3428

Block/Adminhtml/Customer/Edit/ExportButton.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616

1717
class ExportButton extends GenericButton implements ButtonProviderInterface
1818
{
19-
private Config $config;
20-
2119
public function __construct(
2220
Context $context,
2321
Registry $registry,
24-
Config $config
22+
private Config $config
2523
) {
26-
$this->config = $config;
2724
parent::__construct($context, $registry);
2825
}
2926

Block/Adminhtml/Order/Edit/EraseButton.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616

1717
class EraseButton extends AbstractBlock
1818
{
19-
private EraseEntityCheckerInterface $eraseEntityChecker;
20-
2119
public function __construct(
2220
Context $context,
23-
EraseEntityCheckerInterface $eraseEntityChecker,
21+
private EraseEntityCheckerInterface $eraseEntityChecker,
2422
array $data = []
2523
) {
26-
$this->eraseEntityChecker = $eraseEntityChecker;
2724
parent::__construct($context, $data);
2825
}
2926

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

3835
/** @var View $orderView */
3936
$orderView = $this->getLayout()->getBlock('sales_order_edit');
40-
$orderId = (int) $orderView->getOrderId();
37+
$orderId = (int)$orderView->getOrderId();
4138

4239
if ($this->_authorization->isAllowed('Opengento_Gdpr::order_erase') &&
4340
$this->eraseEntityChecker->canCreate($orderId, 'order')

Block/Adminhtml/Order/Edit/ExportButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function _construct(): void
2424

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

2929
if ($this->_authorization->isAllowed('Opengento_Gdpr::order_export')) {
3030
$orderView->addButton(

Controller/Privacy/Erase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function isAllowed(): bool
4141

4242
protected function executeAction(): Page|Redirect
4343
{
44-
if ($this->eraseCustomerChecker->exists((int) $this->customerSession->getCustomerId(), 'customer')) {
44+
if ($this->eraseCustomerChecker->exists((int)$this->customerSession->getCustomerId(), 'customer')) {
4545
$this->messageManager->addErrorMessage(new Phrase('Your account is already being removed.'));
4646
/** @var Redirect $resultRedirect */
4747
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

Cron/EraseEntityScheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ private function scheduleEntitiesErasure(): void
8383

8484
private function resolveErasureMaxAge(): int
8585
{
86-
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE);
86+
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_MAX_AGE, ScopeInterface::SCOPE_STORE);
8787
}
8888
}

Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function isErasureEnabled(): bool
5151
*/
5252
public function getAllowedStatesToErase(): array
5353
{
54-
return explode(',', (string) $this->scopeConfig->getValue(
54+
return explode(',', (string)$this->scopeConfig->getValue(
5555
self::CONFIG_PATH_ERASURE_ALLOWED_STATES,
5656
ScopeInterface::SCOPE_STORE
5757
));

Model/Customer/Anonymize/Processor/CustomerDataProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function anonymizeCustomer(CustomerInterface $customer): void
106106
$secureData = $this->customerRegistry->retrieveSecureData($customer->getId());
107107
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
108108
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
109-
$secureData->setPasswordHash(sha1(uniqid((string) mt_rand(), true)));
109+
$secureData->setPasswordHash(sha1(uniqid((string)mt_rand(), true)));
110110

111111
$customer = $this->anonymizer->anonymize($customer);
112112
if ($customer instanceof DataObject) {

Model/Customer/Anonymize/Processor/OrderDataProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function execute(int $customerId): bool
5858
foreach ($orderList->getItems() as $order) {
5959
$lastActive = new DateTime($order->getUpdatedAt());
6060
$this->salesInformation->isAlive($lastActive)
61-
? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive)
61+
? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive)
6262
: $this->anonymize($order);
6363
}
6464

Model/Customer/CustomerChecker.php

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,24 @@
77

88
namespace Opengento\Gdpr\Model\Customer;
99

10-
use Magento\Framework\Api\SearchCriteriaBuilder;
1110
use Magento\Sales\Api\Data\OrderInterface;
12-
use Magento\Sales\Api\OrderRepositoryInterface;
11+
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
1312
use Opengento\Gdpr\Model\Config;
1413
use Opengento\Gdpr\Model\Entity\EntityCheckerInterface;
1514

1615
class CustomerChecker implements EntityCheckerInterface
1716
{
18-
private OrderRepositoryInterface $orderRepository;
19-
20-
private SearchCriteriaBuilder $criteriaBuilder;
21-
22-
private Config $config;
23-
24-
/**
25-
* @var bool[]
26-
*/
27-
private array $cache;
28-
2917
public function __construct(
30-
OrderRepositoryInterface $orderRepository,
31-
SearchCriteriaBuilder $criteriaBuilder,
32-
Config $config
33-
) {
34-
$this->orderRepository = $orderRepository;
35-
$this->criteriaBuilder = $criteriaBuilder;
36-
$this->config = $config;
37-
$this->cache = [];
38-
}
18+
private CollectionFactory $collectionFactory,
19+
private Config $config
20+
) {}
3921

4022
public function canErase(int $customerId): bool
4123
{
42-
if (!isset($this->cache[$customerId])) {
43-
$this->criteriaBuilder->addFilter(OrderInterface::STATE, $this->config->getAllowedStatesToErase(), 'nin');
44-
$this->criteriaBuilder->addFilter(OrderInterface::CUSTOMER_ID, $customerId);
45-
$orderList = $this->orderRepository->getList($this->criteriaBuilder->create());
46-
47-
$this->cache[$customerId] = !$orderList->getTotalCount();
48-
}
24+
$collection = $this->collectionFactory->create();
25+
$collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $customerId);
26+
$collection->addFieldToFilter(OrderInterface::STATE, ['nin' => $this->config->getAllowedStatesToErase()]);
4927

50-
return $this->cache[$customerId];
28+
return $collection->getSize() > 0;
5129
}
5230
}

Model/Customer/Delete/Processor/OrderDataProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function execute(int $customerId): bool
4545
foreach ($orderList->getItems() as $order) {
4646
$lastActive = new DateTime($order->getUpdatedAt());
4747
$this->salesInformation->isAlive($lastActive)
48-
? $this->salesInformation->scheduleEraseEntity((int) $order->getEntityId(), 'order', $lastActive)
48+
? $this->salesInformation->scheduleEraseEntity((int)$order->getEntityId(), 'order', $lastActive)
4949
: $this->orderRepository->delete($order);
5050
}
5151

Model/Customer/Notifier/MailSender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
*/
4343
public function send(CustomerInterface $customer): void
4444
{
45-
$storeId = $customer->getStoreId() === null ? null : (int) $customer->getStoreId();
45+
$storeId = $customer->getStoreId() === null ? null : (int)$customer->getStoreId();
4646
$vars = [
4747
'customer' => $customer,
4848
'store' => $this->storeManager->getStore($customer->getStoreId()),

Model/Customer/OrigDataRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function get(int $customerId): ?CustomerInterface
2323

2424
public function set(CustomerInterface $customer): void
2525
{
26-
$this->customers[(int) $customer->getId()] = $customer;
26+
$this->customers[(int)$customer->getId()] = $customer;
2727
}
2828
}

Model/Erase/EraseEntityScheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function schedule(array $entityTypes, Filter $filter): void
4747
*/
4848
foreach ($this->collectEntityIds($entityTypes, $filter) as $entityType => $entityIds) {
4949
foreach ($entityIds as $entityId) {
50-
$this->eraseManagement->create((int) $entityId, $entityType);
50+
$this->eraseManagement->create((int)$entityId, $entityType);
5151
}
5252
}
5353
}

Model/Erase/EraseSalesInformation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public function isAlive(DateTimeInterface $lastActive): bool
6262

6363
private function resolveErasureSalesMaxAge(): int
6464
{
65-
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE, ScopeInterface::SCOPE_STORE);
65+
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_SALES_MAX_AGE, ScopeInterface::SCOPE_STORE);
6666
}
6767
}

Model/EraseEntity.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function _construct(): void
2222

2323
public function getEraseId(): int
2424
{
25-
return (int) $this->getId();
25+
return (int)$this->getId();
2626
}
2727

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

3333
public function getEntityId(): int
3434
{
35-
return (int) $this->_getData(self::ENTITY_ID);
35+
return (int)$this->_getData(self::ENTITY_ID);
3636
}
3737

3838
public function setEntityId($entityId): EraseEntityInterface
@@ -42,7 +42,7 @@ public function setEntityId($entityId): EraseEntityInterface
4242

4343
public function getEntityType(): string
4444
{
45-
return (string) $this->_getData(self::ENTITY_TYPE);
45+
return (string)$this->_getData(self::ENTITY_TYPE);
4646
}
4747

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

5353
public function getScheduledAt(): string
5454
{
55-
return (string) $this->_getData(self::SCHEDULED_AT);
55+
return (string)$this->_getData(self::SCHEDULED_AT);
5656
}
5757

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

6363
public function getState(): string
6464
{
65-
return (string) $this->_getData(self::STATE);
65+
return (string)$this->_getData(self::STATE);
6666
}
6767

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

7373
public function getStatus(): string
7474
{
75-
return (string) $this->_getData(self::STATUS);
75+
return (string)$this->_getData(self::STATUS);
7676
}
7777

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

8383
public function getMessage(): ?string
8484
{
85-
return $this->_getData(self::MESSAGE) === null ? null : (string) $this->_getData(self::MESSAGE);
85+
return $this->_getData(self::MESSAGE) === null ? null : (string)$this->_getData(self::MESSAGE);
8686
}
8787

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

9393
public function getErasedAt(): string
9494
{
95-
return (string) $this->_getData(self::ERASED_AT);
95+
return (string)$this->_getData(self::ERASED_AT);
9696
}
9797

9898
public function setErasedAt(string $erasedAt): EraseEntityInterface

Model/EraseEntityChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
public function exists(int $entityId, string $entityType): bool
3434
{
3535
try {
36-
return (bool) $this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId();
36+
return (bool)$this->eraseRepository->getByEntity($entityId, $entityType)->getEraseId();
3737
} catch (NoSuchEntityException $e) {
3838
return false;
3939
}

Model/EraseEntityManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ private function retrieveScheduledAt(): string
122122

123123
private function resolveErasureDelay(): int
124124
{
125-
return (int) $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
125+
return (int)$this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_DELAY, ScopeInterface::SCOPE_STORE);
126126
}
127127
}

Model/Export/ExportToFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function export(ExportEntityInterface $exportEntity): string
7171

7272
public function resolveExportRendererCodes(): array
7373
{
74-
return explode(',', (string) $this->scopeConfig->getValue(
74+
return explode(',', (string)$this->scopeConfig->getValue(
7575
self::CONFIG_PATH_EXPORT_RENDERERS,
7676
ScopeInterface::SCOPE_STORE
7777
));

0 commit comments

Comments
 (0)