diff --git a/ci/qa/phpstan-baseline.neon b/ci/qa/phpstan-baseline.neon
index f77247b0..f01b6f4f 100644
--- a/ci/qa/phpstan-baseline.neon
+++ b/ci/qa/phpstan-baseline.neon
@@ -26,30 +26,15 @@ parameters:
path: ../../dev/Command/AuthenticationCommand.php
-
- message: "#^Cannot access offset string on mixed\\.$#"
- count: 2
- path: ../../dev/Command/AuthenticationCommand.php
-
- -
- message: "#^Comparison operation \"\\>\\=\" between int\\<0, max\\>\\|false and 0 is always true\\.$#"
- count: 1
- path: ../../dev/Command/AuthenticationCommand.php
-
- -
- message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\AuthenticationCommand\\:\\:decorateResult\\(\\) has parameter \\$text with no type specified\\.$#"
+ message: "#^Cannot access offset int\\|string\\|false on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php
-
- message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\AuthenticationCommand\\:\\:readAuthenticationLinkFromFile\\(\\) should return string but returns mixed\\.$#"
+ message: "#^Cannot access offset string on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php
- -
- message: "#^Method Symfony\\\\Component\\\\Console\\\\Input\\\\InputInterface\\:\\:getOption\\(\\) invoked with 2 parameters, 1 required\\.$#"
- count: 2
- path: ../../dev/Command/AuthenticationCommand.php
-
-
message: "#^Parameter \\#1 \\$array of function array_keys expects array, mixed given\\.$#"
count: 1
@@ -85,11 +70,6 @@ parameters:
count: 1
path: ../../dev/Command/AuthenticationCommand.php
- -
- message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
- count: 1
- path: ../../dev/Command/AuthenticationCommand.php
-
-
message: "#^Cannot access offset 'authenticationUrl' on mixed\\.$#"
count: 1
@@ -115,11 +95,6 @@ parameters:
count: 2
path: ../../dev/Command/RegistrationCommand.php
- -
- message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\RegistrationCommand\\:\\:decorateResult\\(\\) has parameter \\$text with no type specified\\.$#"
- count: 1
- path: ../../dev/Command/RegistrationCommand.php
-
-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\RegistrationCommand\\:\\:storeIdentity\\(\\) has parameter \\$metadata with no type specified\\.$#"
count: 1
@@ -215,25 +190,10 @@ parameters:
count: 1
path: ../../dev/FileLogger.php
- -
- message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#"
- count: 1
- path: ../../dev/FileLogger.php
-
-
message: "#^Parameter \\#1 \\$stream of static method League\\\\Csv\\\\AbstractCsv\\:\\:createFromStream\\(\\) expects resource, resource\\|false given\\.$#"
- count: 2
- path: ../../dev/FileLogger.php
-
- -
- message: "#^Cannot call method getEntityId\\(\\) on Surfnet\\\\SamlBundle\\\\Entity\\\\IdentityProvider\\|null\\.$#"
count: 1
- path: ../../dev/Twig/GsspExtension.php
-
- -
- message: "#^Parameter \\#1 \\$string of function urlencode expects string, string\\|null given\\.$#"
- count: 1
- path: ../../dev/Twig/GsspExtension.php
+ path: ../../dev/FileLogger.php
-
message: "#^Parameter \\#3 \\$response of method Surfnet\\\\Tiqr\\\\Tiqr\\\\AuthenticationRateLimitServiceInterface\\:\\:authenticate\\(\\) expects string, mixed given\\.$#"
diff --git a/dev/Command/AuthenticationCommand.php b/dev/Command/AuthenticationCommand.php
index 3667bcd4..a981d8e7 100644
--- a/dev/Command/AuthenticationCommand.php
+++ b/dev/Command/AuthenticationCommand.php
@@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
[$serviceId, $session, $challenge, $sp, $version] = explode('/', $authn);
$userId = null;
- if (strpos($serviceId, '@') >= 0) {
+ if (str_contains($serviceId, '@')) {
[$userId, $serviceId] = explode('@', $serviceId);
}
@@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'sp' => $sp,
'version' => $version,
'userId' => $userId,
- ], JSON_PRETTY_PRINT)),
+ ], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
$service = $this->getService($serviceId);
@@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$service['id'] = $serviceId;
$output->writeln([
'Generate OCRA for service:',
- $this->decorateResult(json_encode($service, JSON_PRETTY_PRINT)),
+ $this->decorateResult(json_encode($service, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
$response = OCRA::generateOCRA($ocraSuite, $secret, '', $challenge, '', $session, '');
@@ -143,8 +143,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'sessionKey' => $session,
'userId' => $userId,
'response' => $response,
- 'notificationType' => $input->getOption('notificationType', ''),
- 'notificationAddress' => $input->getOption('notificationAddress', ''),
+ 'notificationType' => $input->getOption('notificationType'),
+ 'notificationAddress' => $input->getOption('notificationAddress'),
];
$output->writeln([
@@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Send authentication data to "%s" with body:',
$authenticationUrl
),
- $this->decorateResult(json_encode($authenticationBody, JSON_PRETTY_PRINT)),
+ $this->decorateResult(json_encode($authenticationBody, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
$result = $this->client->post($authenticationUrl, [
@@ -166,7 +166,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}
- protected function decorateResult($text): string
+ protected function decorateResult(string $text): string
{
return "$text>";
}
@@ -177,6 +177,10 @@ protected function readAuthenticationLinkFromFile(string $file, OutputInterface
/** @phpstan-var mixed $link */
$link = $qrcode->text();
+ if (!is_string($link)) {
+ throw new RuntimeException('Unable to read a link from the QR code');
+ }
+
$output->writeln([
'Registration link result: ',
$this->decorateResult($link),
diff --git a/dev/Command/RegistrationCommand.php b/dev/Command/RegistrationCommand.php
index b6b1516e..47df043b 100644
--- a/dev/Command/RegistrationCommand.php
+++ b/dev/Command/RegistrationCommand.php
@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$metadata = json_decode($metadataBody);
$output->writeln([
'Metadata result:',
- $this->decorateResult(json_encode($metadata, JSON_PRETTY_PRINT)),
+ $this->decorateResult(json_encode($metadata, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
if ($metadata === false) {
$output->writeln('Metadata has expired');
@@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Send registration data to enrollmentUrl "%s" with body:',
$metadata->service->enrollmentUrl
),
- $this->decorateResult(json_encode($registrationBody, JSON_PRETTY_PRINT)),
+ $this->decorateResult(json_encode($registrationBody, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
$result = $this->client->post($metadata->service->enrollmentUrl, ['form_params' => $registrationBody]);
@@ -121,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}
- protected function decorateResult($text): string
+ protected function decorateResult(string $text): string
{
return "$text>";
}
diff --git a/dev/FileLogger.php b/dev/FileLogger.php
index 001702de..372a4a04 100644
--- a/dev/FileLogger.php
+++ b/dev/FileLogger.php
@@ -36,6 +36,10 @@ public function log($level, $message, array $context = []): void
return;
}
$file = fopen($this->getCSVFile(), 'ab+');
+ if (!$file) {
+ return;
+ }
+
$csv = Writer::createFromStream($file);
$csv->setDelimiter(';');
$csv->insertOne([$level, $message, json_encode($context)]);
diff --git a/dev/Twig/GsspExtension.php b/dev/Twig/GsspExtension.php
index d4041163..0b2d7ac2 100644
--- a/dev/Twig/GsspExtension.php
+++ b/dev/Twig/GsspExtension.php
@@ -38,7 +38,7 @@ public function generateDemoSPUrl(): string
{
return sprintf(
'https://pieter.aai.surfnet.nl/simplesamlphp/sp.php?idp=%s',
- urlencode($this->hostedEntities->getIdentityProvider()->getEntityId())
+ urlencode($this->hostedEntities->getIdentityProvider()?->getEntityId() ?? '')
);
}
}