Skip to content

Commit 3b7dec5

Browse files
committed
Phpcs fix
1 parent 91730b5 commit 3b7dec5

File tree

5 files changed

+50
-71
lines changed

5 files changed

+50
-71
lines changed

.github/workflows/mess-detector.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10-
- uses: extdn/github-actions-m2/magento-mess-detector/8.2@master
10+
- uses: extdn/github-actions-m2/magento-mess-detector/@master

Model/Customer/Anonymize/Processor/CustomerDataProcessor.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
use Opengento\Gdpr\Model\Customer\OrigDataRegistry;
2828
use Opengento\Gdpr\Service\Anonymize\AnonymizerInterface;
2929
use Opengento\Gdpr\Service\Erase\ProcessorInterface;
30+
use Random\RandomException;
3031

31-
use function mt_rand;
32+
use function random_int;
3233
use function sha1;
3334
use function uniqid;
3435

@@ -50,18 +51,18 @@ public function __construct(
5051
) {}
5152

5253
/**
53-
* @inheritdoc
5454
* @throws LocalizedException
55+
* @throws RandomException
5556
*/
56-
public function execute(int $customerId): bool
57+
public function execute(int $entityId): bool
5758
{
5859
try {
59-
$this->processCustomerData($customerId);
60-
} catch (NoSuchEntityException $e) {
60+
$this->processCustomerData($entityId);
61+
} catch (NoSuchEntityException) {
6162
return false;
6263
}
6364

64-
$this->sessionCleaner->clearFor($customerId);
65+
$this->sessionCleaner->clearFor($entityId);
6566

6667
return true;
6768
}
@@ -71,6 +72,7 @@ public function execute(int $customerId): bool
7172
* @throws InputMismatchException
7273
* @throws LocalizedException
7374
* @throws NoSuchEntityException
75+
* @throws RandomException
7476
*/
7577
private function processCustomerData(int $customerId): void
7678
{
@@ -98,6 +100,7 @@ private function fetchOrdersList(CustomerInterface $customer): OrderSearchResult
98100
* @throws NoSuchEntityException
99101
* @throws InputException
100102
* @throws InputMismatchException
103+
* @throws RandomException
101104
*/
102105
private function anonymizeCustomer(CustomerInterface $customer): void
103106
{
@@ -106,7 +109,7 @@ private function anonymizeCustomer(CustomerInterface $customer): void
106109
$secureData = $this->customerRegistry->retrieveSecureData($customer->getId());
107110
$dateTime = (new DateTime())->setTimestamp(PHP_INT_MAX);
108111
$secureData->setData('lock_expires', $dateTime->format(DateTimeFormat::DATETIME_PHP_FORMAT));
109-
$secureData->setPasswordHash(sha1(uniqid((string)mt_rand(), true)));
112+
$secureData->setPasswordHash(sha1(uniqid((string)random_int(), true)));
110113

111114
$customer = $this->anonymizer->anonymize($customer);
112115
if ($customer instanceof DataObject) {

Service/Anonymize/Anonymizer/Anonymous.php

+10-21
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,24 @@
1414

1515
class Anonymous implements AnonymizerInterface
1616
{
17-
private const PHRASE = '%1Anonymous%2';
18-
private const PREFIX_LENGTH = 3;
19-
private const SUFFIX_LENGTH = 2;
17+
public function __construct(private Random $mathRandom) {}
2018

2119
/**
22-
* @var Random
20+
* @throws LocalizedException
2321
*/
24-
private Random $mathRandom;
25-
26-
public function __construct(
27-
Random $mathRandom
28-
) {
29-
$this->mathRandom = $mathRandom;
22+
public function anonymize($value): ?string
23+
{
24+
return $value ? $this->createPhrase()->render() : null;
3025
}
3126

3227
/**
33-
* @inheritdoc
3428
* @throws LocalizedException
3529
*/
36-
public function anonymize($value): ?string
30+
private function createPhrase(): Phrase
3731
{
38-
return $value
39-
? (new Phrase(
40-
self::PHRASE,
41-
[
42-
$this->mathRandom->getRandomString(self::PREFIX_LENGTH),
43-
$this->mathRandom->getRandomString(self::SUFFIX_LENGTH),
44-
]
45-
))->render()
46-
: null;
32+
return new Phrase(
33+
'%1Anonymous%2',
34+
[$this->mathRandom->getRandomString(3), $this->mathRandom->getRandomString(2)]
35+
);
4736
}
4837
}

Service/Anonymize/Anonymizer/Email.php

+13-21
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,27 @@
1414

1515
class Email implements AnonymizerInterface
1616
{
17-
private const PHRASE = '%1-anonymous-%[email protected]';
18-
private const PREFIX_LENGTH = 3;
19-
private const SUFFIX_LENGTH = 2;
17+
public function __construct(private Random $mathRandom) {}
2018

2119
/**
22-
* @var Random
20+
* @throws LocalizedException
2321
*/
24-
private Random $mathRandom;
25-
26-
public function __construct(
27-
Random $mathRandom
28-
) {
29-
$this->mathRandom = $mathRandom;
22+
public function anonymize($value): ?string
23+
{
24+
return $value ? $this->createPhrase()->render() : null;
3025
}
3126

3227
/**
33-
* @inheritdoc
3428
* @throws LocalizedException
3529
*/
36-
public function anonymize($value): ?string
30+
private function createPhrase(): Phrase
3731
{
38-
return $value
39-
? (new Phrase(
40-
self::PHRASE,
41-
[
42-
$this->mathRandom->getRandomString(self::PREFIX_LENGTH, Random::CHARS_LOWERS),
43-
$this->mathRandom->getRandomString(self::SUFFIX_LENGTH, Random::CHARS_LOWERS),
44-
]
45-
))->render()
46-
: null;
32+
return new Phrase(
33+
'%1-anonymous-%[email protected]',
34+
[
35+
$this->mathRandom->getRandomString(3, Random::CHARS_LOWERS),
36+
$this->mathRandom->getRandomString(2, Random::CHARS_LOWERS)
37+
]
38+
);
4739
}
4840
}

Service/Anonymize/Anonymizer/Entity.php

+16-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Exception;
1111
use InvalidArgumentException;
12+
use Magento\Framework\EntityManager\HydratorInterface;
1213
use Magento\Framework\EntityManager\HydratorPool;
1314
use Magento\Framework\EntityManager\TypeResolver;
1415
use Opengento\Gdpr\Model\Entity\DataCollectorInterface;
@@ -20,37 +21,31 @@
2021

2122
class Entity implements AnonymizerInterface
2223
{
23-
private DataCollectorInterface $dataCollector;
24-
25-
private TypeResolver $typeResolver;
26-
27-
private HydratorPool $hydratorPool;
28-
2924
public function __construct(
30-
DataCollectorInterface $dataCollector,
31-
TypeResolver $typeResolver,
32-
HydratorPool $hydratorPool
33-
) {
34-
$this->dataCollector = $dataCollector;
35-
$this->typeResolver = $typeResolver;
36-
$this->hydratorPool = $hydratorPool;
37-
}
25+
private DataCollectorInterface $dataCollector,
26+
private TypeResolver $typeResolver,
27+
private HydratorPool $hydratorPool
28+
) {}
3829

3930
/**
40-
* @inheritdoc
4131
* @throws Exception
4232
*/
43-
public function anonymize($entity): object
33+
public function anonymize($value): object
4434
{
45-
if (!is_object($entity)) {
35+
if (!is_object($value)) {
4636
throw new InvalidArgumentException(
47-
sprintf('Argument "$entity" must be an object, type "%s" given.', gettype($entity))
37+
sprintf('Argument "$entity" must be an object, type "%s" given.', gettype($value))
4838
);
4939
}
5040

51-
$hydrator = $this->hydratorPool->getHydrator($this->typeResolver->resolve($entity));
52-
$hydrator->hydrate($entity, $this->dataCollector->collect($entity));
41+
return $this->resolveHydrator($value)->hydrate($value, $this->dataCollector->collect($value));
42+
}
5343

54-
return $entity;
44+
/**
45+
* @throws Exception
46+
*/
47+
private function resolveHydrator(object $entity): HydratorInterface
48+
{
49+
return $this->hydratorPool->getHydrator($this->typeResolver->resolve($entity));
5550
}
5651
}

0 commit comments

Comments
 (0)