diff --git a/src/Controller/Account/PersonalDataController.php b/src/Controller/Account/PersonalDataController.php index e96890d..0e3ae87 100644 --- a/src/Controller/Account/PersonalDataController.php +++ b/src/Controller/Account/PersonalDataController.php @@ -105,7 +105,7 @@ class PersonalDataController extends AbstractController return $this->redirectToRoute('app_personal_data'); } - if ($updateResult instanceof PersonalDataUpdateResponse && false === $updateResult->changed) { + if (false === $updateResult->changed) { $this->logger->error('BPN did not apply personal data update', [ 'email' => $user->getEmail(), 'addressId' => $updateResult->addressId, diff --git a/src/Controller/Traits/ReturnUrlTrait.php b/src/Controller/Traits/ReturnUrlTrait.php index 85efaca..d6c0384 100644 --- a/src/Controller/Traits/ReturnUrlTrait.php +++ b/src/Controller/Traits/ReturnUrlTrait.php @@ -6,6 +6,9 @@ use Symfony\Component\HttpFoundation\Request; trait ReturnUrlTrait { + /** + * @param array $parameters + */ public function getReturnUrl(Request $request, string $defaultRoute, array $parameters = []): string { $defaultUrl = $this->generateUrl($defaultRoute, $parameters); diff --git a/src/Menu/AbstractMenuBuilder.php b/src/Menu/AbstractMenuBuilder.php index 49a9d90..dd71df0 100644 --- a/src/Menu/AbstractMenuBuilder.php +++ b/src/Menu/AbstractMenuBuilder.php @@ -24,6 +24,9 @@ abstract class AbstractMenuBuilder return $this->factory->createItem('root'); } + /** + * @return array + */ protected function getDefaultRouteParameters(string $parameter = 'id', string $default = '0'): array { $request = $this->requestStack->getMainRequest(); diff --git a/src/Menu/AdminMenuBuilder.php b/src/Menu/AdminMenuBuilder.php index 74b29b6..a480b02 100644 --- a/src/Menu/AdminMenuBuilder.php +++ b/src/Menu/AdminMenuBuilder.php @@ -6,6 +6,9 @@ use Knp\Menu\ItemInterface; class AdminMenuBuilder extends AbstractMenuBuilder { + /** + * @param array $options + */ public function createMainMenu(array $options): ItemInterface { $menu = $this->createRootElement(); diff --git a/src/Service/BpnXmlAnonymizer.php b/src/Service/BpnXmlAnonymizer.php index b031aa5..2e8ee44 100644 --- a/src/Service/BpnXmlAnonymizer.php +++ b/src/Service/BpnXmlAnonymizer.php @@ -10,41 +10,11 @@ use Faker\Generator; class BpnXmlAnonymizer { private const SAFE_EMAIL_DOMAIN = 'example.com'; - private const SALUTATIONS = ['Herr', 'Frau', 'Divers']; - private const GENDERS = ['M', 'W', 'D']; - private const COUNTRY_CODES = ['AT', 'BE', 'CH', 'DE', 'DK', 'ES', 'FR', 'IT', 'NL', 'NO', 'PL', 'SE']; private Generator $faker; /** - * @var array + * @var array> */ private array $identities = []; @@ -141,24 +111,9 @@ class BpnXmlAnonymizer } } - $currentNode = $personNode; - while ($currentNode instanceof \DOMElement) { - foreach (['personid', 'idperson', 'idadresseperson'] as $tagName) { - $child = $this->getDirectChild($currentNode, $tagName); - if (null !== $child) { - $value = trim($child->textContent); - if ('' !== $value) { - return $value; - } - } - } - - $parentNode = $currentNode->parentNode; - if (false === $parentNode instanceof \DOMElement) { - break; - } - - $currentNode = $parentNode; + $personIdValue = $this->findPersonIdInAncestors($personNode); + if (null !== $personIdValue) { + return $personIdValue; } $fingerprintKey = $this->buildFingerprintKey($personNode); @@ -232,34 +187,7 @@ class BpnXmlAnonymizer } /** - * @return array{ - * firstName: string, - * lastName: string, - * salutation: string, - * title: string, - * gender: string, - * nationality: string, - * birthDate: string, - * street: string, - * postalCode: string, - * city: string, - * district: string, - * country: string, - * email: string, - * mobilePhone: string, - * phone: string, - * newsletter: string, - * iban: string, - * userName: string, - * requestKey: string, - * requestPassword: string, - * personId: string, - * addressId: string, - * customerId: string, - * height: string, - * weight: string, - * shoeSize: string - * } + * @return array */ private function getOrCreateIdentity(string $personId): array { @@ -330,7 +258,7 @@ class BpnXmlAnonymizer } /** - * @param array{firstName: string, lastName: string, street: string, postalCode: string, city: string, email: string, mobilePhone: string} $identity + * @param array $identity */ private function replaceNameFields(\DOMElement $personNode, array $identity): void { @@ -358,7 +286,7 @@ class BpnXmlAnonymizer } /** - * @param array{firstName: string, lastName: string, street: string, postalCode: string, city: string, email: string, mobilePhone: string} $identity + * @param array $identity */ private function replaceEmailFields(\DOMElement $personNode, array $identity): void { @@ -396,7 +324,7 @@ class BpnXmlAnonymizer } /** - * @param array{firstName: string, lastName: string, street: string, postalCode: string, city: string, email: string, mobilePhone: string} $identity + * @param array $identity */ private function replaceAddressFields(\DOMElement $personNode, array $identity): void { @@ -436,6 +364,9 @@ class BpnXmlAnonymizer } } + /** + * @param array $identity + */ private function replaceDemographicFields(\DOMElement $personNode, array $identity): void { $salutationNode = $this->getDirectChild($personNode, 'anrede'); @@ -479,6 +410,9 @@ class BpnXmlAnonymizer } } + /** + * @param array $identity + */ private function replaceFinancialFields(\DOMElement $personNode, array $identity): void { $bankNode = $this->getDirectChild($personNode, 'bankverbindung'); @@ -492,6 +426,9 @@ class BpnXmlAnonymizer } } + /** + * @param array $identity + */ private function replaceMetadataFields(\DOMElement $personNode, array $identity): void { if (true === $personNode->hasAttribute('id')) { @@ -503,6 +440,9 @@ class BpnXmlAnonymizer } } + /** + * @param array $identity + */ private function replaceRequestFields(\DOMElement $personNode, array $identity): void { $userNode = $this->getDirectChild($personNode, 'user'); @@ -544,23 +484,24 @@ class BpnXmlAnonymizer $node->setAttribute($attributeName, $replacement); } - private function findAncestorDirectChild(\DOMElement $personNode, string $ancestorTagName, string $childTagName): ?\DOMElement + private function findPersonIdInAncestors(\DOMElement $node): ?string { - $currentNode = $personNode; - while ($currentNode instanceof \DOMElement) { - if ($ancestorTagName === $currentNode->tagName) { - return $this->getDirectChild($currentNode, $childTagName); + foreach (['personid', 'idperson', 'idadresseperson'] as $tagName) { + $child = $this->getDirectChild($node, $tagName); + if (null !== $child) { + $value = trim($child->textContent); + if ('' !== $value) { + return $value; + } } - - $parentNode = $currentNode->parentNode; - if (false === $parentNode instanceof \DOMElement) { - break; - } - - $currentNode = $parentNode; } - return null; + $parent = $node->parentNode; + if (false === $parent instanceof \DOMElement) { + return null; + } + + return $this->findPersonIdInAncestors($parent); } private function getDirectChild(\DOMElement $parent, string $name): ?\DOMElement @@ -578,21 +519,4 @@ class BpnXmlAnonymizer return null; } - private function slug(string $value): string - { - $normalizedValue = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value); - if (false === $normalizedValue) { - $normalizedValue = $value; - } - - $normalizedValue = strtolower($normalizedValue); - $normalizedValue = preg_replace('/[^a-z0-9]+/', '.', $normalizedValue); - $normalizedValue = trim((string) $normalizedValue, '.'); - - if ('' === $normalizedValue) { - return 'user'; - } - - return $normalizedValue; - } } diff --git a/src/Service/DatabaseAnonymizer.php b/src/Service/DatabaseAnonymizer.php index ca7ed11..7758139 100644 --- a/src/Service/DatabaseAnonymizer.php +++ b/src/Service/DatabaseAnonymizer.php @@ -48,6 +48,9 @@ class DatabaseAnonymizer $this->identitySequence = 0; } + /** + * @return array{users: int, newsletterConsents: int, newsletterOptInRequests: int, bookingEditDrafts: int} + */ public function anonymizeAll(int $batchSize = self::DEFAULT_BATCH_SIZE): array { if ($batchSize < 1) { @@ -405,6 +408,9 @@ class DatabaseAnonymizer return null !== $this->stringOrNull($value); } + /** + * @param array $identity + */ private function placeholderText(array $identity, string $suffix): string { return sprintf('%s-%s', $identity['lastName'], $suffix);