Skip to content

Commit 24eb487

Browse files
committed
Fix nullable properties
1 parent 22d90fd commit 24eb487

10 files changed

+57
-179
lines changed

Model/Customer/CustomerChecker.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Opengento\Gdpr\Model\Customer;
99

10+
use Magento\Customer\Api\CustomerRepositoryInterface;
1011
use Magento\Sales\Api\Data\OrderInterface;
1112
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
1213
use Opengento\Gdpr\Model\Config\Entity\Erasure as ErasureConfig;
@@ -15,15 +16,20 @@
1516
class CustomerChecker implements EntityCheckerInterface
1617
{
1718
public function __construct(
19+
private CustomerRepositoryInterface $customerRepository,
1820
private CollectionFactory $collectionFactory,
1921
private ErasureConfig $erasureConfig
2022
) {}
2123

2224
public function canErase(int $entityId): bool
2325
{
26+
$customer = $this->customerRepository->getById($entityId);
2427
$collection = $this->collectionFactory->create();
2528
$collection->addFieldToFilter(OrderInterface::CUSTOMER_ID, $entityId);
26-
$collection->addFieldToFilter(OrderInterface::STATE, ['nin' => $this->erasureConfig->getAllowedStatesToErase()]);//ToDo scope Website
29+
$collection->addFieldToFilter(
30+
OrderInterface::STATE,
31+
['nin' => $this->erasureConfig->getAllowedStatesToErase($customer->getWebsiteId())]
32+
);
2733

2834
return $collection->getSize() > 0;
2935
}

Observer/DeleteExport.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,16 @@
2424

2525
class DeleteExport implements ObserverInterface
2626
{
27-
private ExportEntityRepositoryInterface $exportRepository;
28-
29-
private SearchCriteriaBuilder $criteriaBuilder;
30-
31-
private FilterBuilder $filterBuilder;
32-
33-
private EntityTypeResolver $entityTypeResolver;
34-
35-
private LoggerInterface $logger;
36-
3727
public function __construct(
38-
ExportEntityRepositoryInterface $exportRepository,
39-
SearchCriteriaBuilder $criteriaBuilder,
40-
FilterBuilder $filterBuilder,
41-
EntityTypeResolver $entityTypeResolver,
42-
LoggerInterface $logger
43-
) {
44-
$this->exportRepository = $exportRepository;
45-
$this->criteriaBuilder = $criteriaBuilder;
46-
$this->filterBuilder = $filterBuilder;
47-
$this->entityTypeResolver = $entityTypeResolver;
48-
$this->logger = $logger;
49-
}
28+
private ExportEntityRepositoryInterface $exportRepository,
29+
private SearchCriteriaBuilder $criteriaBuilder,
30+
private FilterBuilder $filterBuilder,
31+
private EntityTypeResolver $entityTypeResolver,
32+
private LoggerInterface $logger
33+
) {}
5034

5135
public function execute(Observer $observer): void
5236
{
53-
/** @var DataObject $entity */
5437
$entity = $observer->getData('data_object');
5538

5639
if ($entity instanceof DataObject) {
@@ -67,7 +50,6 @@ public function execute(Observer $observer): void
6750
}
6851

6952
/**
70-
* @param DataObject $entity
7153
* @return ExportEntitySearchResultsInterface
7254
* @throws LocalizedException
7355
* @throws Exception

Observer/InvalidateExport.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,17 @@
2525

2626
class InvalidateExport implements ObserverInterface
2727
{
28-
private ExportEntityRepositoryInterface $exportRepository;
29-
30-
private ExportEntityManagementInterface $exportManagement;
31-
32-
private SearchCriteriaBuilder $criteriaBuilder;
33-
34-
private FilterBuilder $filterBuilder;
35-
36-
private EntityTypeResolver $entityTypeResolver;
37-
38-
private LoggerInterface $logger;
39-
4028
public function __construct(
41-
ExportEntityRepositoryInterface $exportRepository,
42-
ExportEntityManagementInterface $exportManagement,
43-
SearchCriteriaBuilder $criteriaBuilder,
44-
FilterBuilder $filterBuilder,
45-
EntityTypeResolver $entityTypeResolver,
46-
LoggerInterface $logger
47-
) {
48-
$this->exportRepository = $exportRepository;
49-
$this->exportManagement = $exportManagement;
50-
$this->criteriaBuilder = $criteriaBuilder;
51-
$this->filterBuilder = $filterBuilder;
52-
$this->entityTypeResolver = $entityTypeResolver;
53-
$this->logger = $logger;
54-
}
29+
private ExportEntityRepositoryInterface $exportRepository,
30+
private ExportEntityManagementInterface $exportManagement,
31+
private SearchCriteriaBuilder $criteriaBuilder,
32+
private FilterBuilder $filterBuilder,
33+
private EntityTypeResolver $entityTypeResolver,
34+
private LoggerInterface $logger
35+
) {}
5536

5637
public function execute(Observer $observer): void
5738
{
58-
$entity = $observer->getData('data_object');
59-
6039
if ($entity instanceof DataObject) {
6140
try {
6241
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
@@ -71,7 +50,6 @@ public function execute(Observer $observer): void
7150
}
7251

7352
/**
74-
* @param DataObject $entity
7553
* @return ExportEntitySearchResultsInterface
7654
* @throws LocalizedException
7755
* @throws Exception

ViewModel/Customer/Guest/EraseDataProvider.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,22 @@
1414

1515
class EraseDataProvider implements ArgumentInterface
1616
{
17-
private EraseEntityCheckerInterface $eraseEntityChecker;
18-
19-
private Registry $registry;
20-
21-
/**
22-
* @var null|bool
23-
*/
24-
private ?bool $canCancel;
25-
26-
/**
27-
* @var null|bool
28-
*/
29-
private ?bool $canCreate;
17+
private ?bool $canCancel = null;
18+
private ?bool $canCreate = null;
3019

3120
public function __construct(
32-
EraseEntityCheckerInterface $eraseEntityChecker,
33-
Registry $registry
34-
) {
35-
$this->eraseEntityChecker = $eraseEntityChecker;
36-
$this->registry = $registry;
37-
}
21+
private EraseEntityCheckerInterface $eraseEntityChecker,
22+
private Registry $registry
23+
) {}
3824

3925
public function canCancel(): bool
4026
{
41-
return $this->canCancel ??
42-
$this->canCancel = $this->eraseEntityChecker->canCancel($this->currentOrderId(), 'order');
27+
return $this->canCancel ??= $this->eraseEntityChecker->canCancel($this->currentOrderId(), 'order');
4328
}
4429

4530
public function canCreate(): bool
4631
{
47-
return $this->canCreate ??
48-
$this->canCreate = $this->eraseEntityChecker->canCreate($this->currentOrderId(), 'order');
32+
return $this->canCreate ??= $this->eraseEntityChecker->canCreate($this->currentOrderId(), 'order');
4933
}
5034

5135
private function currentOrderId(): int

ViewModel/Customer/Guest/ExportDataProvider.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,22 @@
1414

1515
class ExportDataProvider implements ArgumentInterface
1616
{
17-
private ExportEntityCheckerInterface $exportEntityChecker;
18-
19-
private Registry $registry;
20-
21-
/**
22-
* @var bool|null
23-
*/
24-
private ?bool $isExportEntityExists;
25-
26-
/**
27-
* @var bool|null
28-
*/
29-
private ?bool $isExported;
17+
private ?bool $isExportEntityExists = null;
18+
private ?bool $isExported = null;
3019

3120
public function __construct(
32-
ExportEntityCheckerInterface $exportEntityChecker,
33-
Registry $registry
34-
) {
35-
$this->exportEntityChecker = $exportEntityChecker;
36-
$this->registry = $registry;
37-
}
21+
private ExportEntityCheckerInterface $exportEntityChecker,
22+
private Registry $registry
23+
) {}
3824

3925
public function hasExport(): bool
4026
{
41-
return $this->isExportEntityExists ??
42-
$this->isExportEntityExists = $this->exportEntityChecker->exists($this->currentOrderId(), 'order');
27+
return $this->isExportEntityExists ??= $this->exportEntityChecker->exists($this->currentOrderId(), 'order');
4328
}
4429

4530
public function isExported(): bool
4631
{
47-
return $this->isExported ??
48-
$this->isExported = $this->exportEntityChecker->isExported($this->currentOrderId(), 'order');
32+
return $this->isExported ??= $this->exportEntityChecker->isExported($this->currentOrderId(), 'order');
4933
}
5034

5135
private function currentOrderId(): int

ViewModel/Customer/Privacy/EraseCustomerDataProvider.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,13 @@
1313

1414
class EraseCustomerDataProvider implements ArgumentInterface
1515
{
16-
private EraseEntityCheckerInterface $eraseEntityChecker;
17-
18-
/**
19-
* @var Session
20-
*/
21-
private Session $session;
22-
23-
/**
24-
* @var null|bool
25-
*/
26-
private ?bool $canCancel;
27-
28-
/**
29-
* @var null|bool
30-
*/
31-
private ?bool $canCreate;
16+
private ?bool $canCancel = null;
17+
private ?bool $canCreate = null;
3218

3319
public function __construct(
34-
EraseEntityCheckerInterface $eraseEntityChecker,
35-
Session $session
36-
) {
37-
$this->eraseEntityChecker = $eraseEntityChecker;
38-
$this->session = $session;
39-
}
20+
private EraseEntityCheckerInterface $eraseEntityChecker,
21+
private Session $session
22+
) {}
4023

4124
public function canCancel(): bool
4225
{

ViewModel/Customer/Privacy/EraseDataProvider.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,13 @@ class EraseDataProvider implements ArgumentInterface
1818
private const CONFIG_PATH_ERASURE_INFORMATION_BLOCK = 'gdpr/erasure/block_id';
1919
private const CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK = 'gdpr/anonymize/block_id';
2020

21-
private ScopeConfigInterface $scopeConfig;
22-
23-
private BlockFactory $blockFactory;
24-
25-
private ?string $erasureInformation;
26-
27-
private ?string $anonymizeInformation;
21+
private ?string $erasureInformation = null;
22+
private ?string $anonymizeInformation = null;
2823

2924
public function __construct(
30-
ScopeConfigInterface $scopeConfig,
31-
BlockFactory $blockFactory
32-
) {
33-
$this->scopeConfig = $scopeConfig;
34-
$this->blockFactory = $blockFactory;
35-
}
25+
private ScopeConfigInterface $scopeConfig,
26+
private BlockFactory $blockFactory
27+
) {}
3628

3729
public function getErasureInformationHtml(): string
3830
{

ViewModel/Customer/Privacy/ExportCustomerDataProvider.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,13 @@
1313

1414
class ExportCustomerDataProvider implements ArgumentInterface
1515
{
16-
private ExportEntityCheckerInterface $exportEntityChecker;
17-
18-
/**
19-
* @var Session
20-
*/
21-
private Session $session;
22-
23-
/**
24-
* @var null|bool
25-
*/
26-
private ?bool $isExportEntityExists;
27-
28-
/**
29-
* @var null|bool
30-
*/
31-
private ?bool $isExported;
16+
private ?bool $isExportEntityExists = null;
17+
private ?bool $isExported = null;
3218

3319
public function __construct(
34-
ExportEntityCheckerInterface $exportEntityChecker,
35-
Session $session
36-
) {
37-
$this->exportEntityChecker = $exportEntityChecker;
38-
$this->session = $session;
39-
}
20+
private ExportEntityCheckerInterface $exportEntityChecker,
21+
private Session $session
22+
) {}
4023

4124
public function hasExport(): bool
4225
{

ViewModel/Customer/Privacy/ExportDataProvider.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,12 @@ class ExportDataProvider implements ArgumentInterface
1717
{
1818
private const CONFIG_PATH_EXPORT_INFORMATION_BLOCK = 'gdpr/export/block_id';
1919

20-
private ScopeConfigInterface $scopeConfig;
21-
22-
private BlockFactory $blockFactory;
23-
24-
private ?string $exportInformation;
20+
private ?string $exportInformation = null;
2521

2622
public function __construct(
27-
ScopeConfigInterface $scopeConfig,
28-
BlockFactory $blockFactory
29-
) {
30-
$this->scopeConfig = $scopeConfig;
31-
$this->blockFactory = $blockFactory;
32-
}
23+
private ScopeConfigInterface $scopeConfig,
24+
private BlockFactory $blockFactory
25+
) {}
3326

3427
public function getExportInformationHtml(): string
3528
{

ViewModel/Customer/Privacy/SettingsDataProvider.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,12 @@ class SettingsDataProvider implements ArgumentInterface
1717
{
1818
private const CONFIG_PATH_GENERAL_INFORMATION_BLOCK = 'gdpr/general/block_id';
1919

20-
private ScopeConfigInterface $scopeConfig;
21-
22-
private BlockFactory $blockFactory;
23-
24-
private ?string $informationHtml;
20+
private ?string $informationHtml = null;
2521

2622
public function __construct(
27-
ScopeConfigInterface $scopeConfig,
28-
BlockFactory $blockFactory
29-
) {
30-
$this->scopeConfig = $scopeConfig;
31-
$this->blockFactory = $blockFactory;
32-
}
23+
private ScopeConfigInterface $scopeConfig,
24+
private BlockFactory $blockFactory
25+
) {}
3326

3427
public function getPrivacyInformationHtml(): string
3528
{

0 commit comments

Comments
 (0)