chore: fix cgl issues flagged by phpstan

This commit is contained in:
Björn Fromme
2026-07-10 14:33:09 +02:00
parent f47142c465
commit 2f8701c2e0
6 changed files with 50 additions and 111 deletions
@@ -105,7 +105,7 @@ class PersonalDataController extends AbstractController
return $this->redirectToRoute('app_personal_data'); 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', [ $this->logger->error('BPN did not apply personal data update', [
'email' => $user->getEmail(), 'email' => $user->getEmail(),
'addressId' => $updateResult->addressId, 'addressId' => $updateResult->addressId,
+3
View File
@@ -6,6 +6,9 @@ use Symfony\Component\HttpFoundation\Request;
trait ReturnUrlTrait trait ReturnUrlTrait
{ {
/**
* @param array<string, mixed> $parameters
*/
public function getReturnUrl(Request $request, string $defaultRoute, array $parameters = []): string public function getReturnUrl(Request $request, string $defaultRoute, array $parameters = []): string
{ {
$defaultUrl = $this->generateUrl($defaultRoute, $parameters); $defaultUrl = $this->generateUrl($defaultRoute, $parameters);
+3
View File
@@ -24,6 +24,9 @@ abstract class AbstractMenuBuilder
return $this->factory->createItem('root'); return $this->factory->createItem('root');
} }
/**
* @return array<string, mixed>
*/
protected function getDefaultRouteParameters(string $parameter = 'id', string $default = '0'): array protected function getDefaultRouteParameters(string $parameter = 'id', string $default = '0'): array
{ {
$request = $this->requestStack->getMainRequest(); $request = $this->requestStack->getMainRequest();
+3
View File
@@ -6,6 +6,9 @@ use Knp\Menu\ItemInterface;
class AdminMenuBuilder extends AbstractMenuBuilder class AdminMenuBuilder extends AbstractMenuBuilder
{ {
/**
* @param array<string, mixed> $options
*/
public function createMainMenu(array $options): ItemInterface public function createMainMenu(array $options): ItemInterface
{ {
$menu = $this->createRootElement(); $menu = $this->createRootElement();
+34 -110
View File
@@ -10,41 +10,11 @@ use Faker\Generator;
class BpnXmlAnonymizer class BpnXmlAnonymizer
{ {
private const SAFE_EMAIL_DOMAIN = 'example.com'; 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; private Generator $faker;
/** /**
* @var array<string, array{ * @var array<string, array<string, string>>
* 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
* }>
*/ */
private array $identities = []; private array $identities = [];
@@ -141,24 +111,9 @@ class BpnXmlAnonymizer
} }
} }
$currentNode = $personNode; $personIdValue = $this->findPersonIdInAncestors($personNode);
while ($currentNode instanceof \DOMElement) { if (null !== $personIdValue) {
foreach (['personid', 'idperson', 'idadresseperson'] as $tagName) { return $personIdValue;
$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;
} }
$fingerprintKey = $this->buildFingerprintKey($personNode); $fingerprintKey = $this->buildFingerprintKey($personNode);
@@ -232,34 +187,7 @@ class BpnXmlAnonymizer
} }
/** /**
* @return array{ * @return array<string, string>
* 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
* }
*/ */
private function getOrCreateIdentity(string $personId): 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<string, string> $identity
*/ */
private function replaceNameFields(\DOMElement $personNode, array $identity): void 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<string, string> $identity
*/ */
private function replaceEmailFields(\DOMElement $personNode, array $identity): void 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<string, string> $identity
*/ */
private function replaceAddressFields(\DOMElement $personNode, array $identity): void private function replaceAddressFields(\DOMElement $personNode, array $identity): void
{ {
@@ -436,6 +364,9 @@ class BpnXmlAnonymizer
} }
} }
/**
* @param array<string, string> $identity
*/
private function replaceDemographicFields(\DOMElement $personNode, array $identity): void private function replaceDemographicFields(\DOMElement $personNode, array $identity): void
{ {
$salutationNode = $this->getDirectChild($personNode, 'anrede'); $salutationNode = $this->getDirectChild($personNode, 'anrede');
@@ -479,6 +410,9 @@ class BpnXmlAnonymizer
} }
} }
/**
* @param array<string, string> $identity
*/
private function replaceFinancialFields(\DOMElement $personNode, array $identity): void private function replaceFinancialFields(\DOMElement $personNode, array $identity): void
{ {
$bankNode = $this->getDirectChild($personNode, 'bankverbindung'); $bankNode = $this->getDirectChild($personNode, 'bankverbindung');
@@ -492,6 +426,9 @@ class BpnXmlAnonymizer
} }
} }
/**
* @param array<string, string> $identity
*/
private function replaceMetadataFields(\DOMElement $personNode, array $identity): void private function replaceMetadataFields(\DOMElement $personNode, array $identity): void
{ {
if (true === $personNode->hasAttribute('id')) { if (true === $personNode->hasAttribute('id')) {
@@ -503,6 +440,9 @@ class BpnXmlAnonymizer
} }
} }
/**
* @param array<string, string> $identity
*/
private function replaceRequestFields(\DOMElement $personNode, array $identity): void private function replaceRequestFields(\DOMElement $personNode, array $identity): void
{ {
$userNode = $this->getDirectChild($personNode, 'user'); $userNode = $this->getDirectChild($personNode, 'user');
@@ -544,23 +484,24 @@ class BpnXmlAnonymizer
$node->setAttribute($attributeName, $replacement); $node->setAttribute($attributeName, $replacement);
} }
private function findAncestorDirectChild(\DOMElement $personNode, string $ancestorTagName, string $childTagName): ?\DOMElement private function findPersonIdInAncestors(\DOMElement $node): ?string
{ {
$currentNode = $personNode; foreach (['personid', 'idperson', 'idadresseperson'] as $tagName) {
while ($currentNode instanceof \DOMElement) { $child = $this->getDirectChild($node, $tagName);
if ($ancestorTagName === $currentNode->tagName) { if (null !== $child) {
return $this->getDirectChild($currentNode, $childTagName); $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 private function getDirectChild(\DOMElement $parent, string $name): ?\DOMElement
@@ -578,21 +519,4 @@ class BpnXmlAnonymizer
return null; 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;
}
} }
+6
View File
@@ -48,6 +48,9 @@ class DatabaseAnonymizer
$this->identitySequence = 0; $this->identitySequence = 0;
} }
/**
* @return array{users: int, newsletterConsents: int, newsletterOptInRequests: int, bookingEditDrafts: int}
*/
public function anonymizeAll(int $batchSize = self::DEFAULT_BATCH_SIZE): array public function anonymizeAll(int $batchSize = self::DEFAULT_BATCH_SIZE): array
{ {
if ($batchSize < 1) { if ($batchSize < 1) {
@@ -405,6 +408,9 @@ class DatabaseAnonymizer
return null !== $this->stringOrNull($value); return null !== $this->stringOrNull($value);
} }
/**
* @param array<string, string> $identity
*/
private function placeholderText(array $identity, string $suffix): string private function placeholderText(array $identity, string $suffix): string
{ {
return sprintf('%s-%s', $identity['lastName'], $suffix); return sprintf('%s-%s', $identity['lastName'], $suffix);