Skip to content

Commit b45ae57

Browse files
committed
Fix phpstan issues
1 parent aa65259 commit b45ae57

15 files changed

Lines changed: 316 additions & 188 deletions

ci/qa/phpstan-baseline.neon

Lines changed: 292 additions & 149 deletions
Large diffs are not rendered by default.

ci/qa/rector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
->withPaths([
99
__DIR__ . '/../../src',
1010
])
11-
->withPhpSets()
1211
->withAttributesSets(all: true)
1312
->withComposerBased(phpunit: true, symfony: true)
14-
->withTypeCoverageLevel(0)
13+
->withTypeCoverageLevel(10)
1514
->withDeadCodeLevel(0)
1615
->withCodeQualityLevel(0);

src/DependencyInjection/SurfnetSamlExtension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ private function parseRemoteConfiguration(array $remoteConfiguration, ContainerB
158158
if (!empty($remoteConfiguration['identity_provider']['enabled'])) {
159159
$definition = $this->parseRemoteIdentityProviderConfiguration($remoteConfiguration['identity_provider']);
160160

161-
if ($definition !== null) {
162-
$container->setDefinition('surfnet_saml.remote.idp', $definition);
163-
}
161+
$container->setDefinition('surfnet_saml.remote.idp', $definition);
164162
}
165163
}
166164

src/Http/PostBinding.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
4343

4444
/**
45-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
45+
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
4646
*/
4747
class PostBinding implements HttpBinding
4848
{

src/Http/ReceivedAuthnRequestPost.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ final class ReceivedAuthnRequestPost implements SignatureVerifiable
2828
public const PARAMETER_REQUEST = 'SAMLRequest';
2929
public const PARAMETER_RELAY_STATE = 'RelayState';
3030

31-
private ?string $relayState;
31+
private ?string $relayState = null;
3232

3333
private ?ReceivedAuthnRequest $receivedRequest = null;
3434

35-
private function __construct(private readonly string $samlRequest)
35+
private readonly string $samlRequest;
36+
37+
private function __construct(string $samlRequest)
3638
{
39+
$this->samlRequest = $samlRequest;
3740
}
3841

3942
public static function parse(array $parameters): self
@@ -62,7 +65,7 @@ public function hasRelayState(): bool
6265
return $this->relayState !== null;
6366
}
6467

65-
public function getDecodedSamlRequest(): string|bool
68+
public function getDecodedSamlRequest(): string
6669
{
6770
return base64_decode($this->samlRequest);
6871
}

src/Http/ReceivedAuthnRequestQueryString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ private function __construct(private readonly string $samlRequest)
4949
}
5050

5151
/**
52-
* @SuppressWarnings(PHPMD.CyclomaticComplexity) Extensive validation
53-
* @SuppressWarnings(PHPMD.NPathComplexity) Extensive validation
52+
* @SuppressWarnings("PHPMD.CyclomaticComplexity") Extensive validation
53+
* @SuppressWarnings("PHPMD.NPathComplexity") Extensive validation
5454
*/
5555
public static function parse(string $query): ReceivedAuthnRequestQueryString
5656
{
@@ -211,7 +211,7 @@ public function getSamlRequest(): string
211211
return $this->samlRequest;
212212
}
213213

214-
public function getSignatureAlgorithm(): ?string
214+
public function getSignatureAlgorithm(): string
215215
{
216216
return urldecode($this->signatureAlgorithm);
217217
}

src/Http/RedirectBinding.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
3333

3434
/**
35-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) - not much we can do about it
35+
* @SuppressWarnings("PHPMD.CouplingBetweenObjects") - not much we can do about it
3636
* @see https://www.pivotaltracker.com/story/show/83028366
3737
*/
3838
class RedirectBinding implements HttpBinding
@@ -71,7 +71,7 @@ public function receiveUnsignedAuthnRequestFrom(Request $request): ReceivedAuthn
7171
}
7272

7373
/**
74-
* @SuppressWarnings(PHPMD.NPathComplexity)
74+
* @SuppressWarnings("PHPMD.NPathComplexity")
7575
*/
7676
public function receiveSignedAuthnRequestFrom(Request $request): ReceivedAuthnRequest
7777
{

src/Metadata/MetadataFactory.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ private function buildMetadata(): Metadata
7272
$metadata->hasSpMetadata = true;
7373
$metadata->assertionConsumerUrl = $this->getUrl($metadataConfiguration->assertionConsumerRoute);
7474

75-
if ($metadataConfiguration->spCertificate &&
76-
$metadataConfiguration->spCertificate !== '' &&
77-
$metadataConfiguration->spCertificate !== '0'
78-
) {
75+
if ($metadataConfiguration->spCertificate) {
7976
$metadata->spCertificate = $this->getCertificateData($metadataConfiguration->spCertificate);
8077
}
8178
}
@@ -84,10 +81,7 @@ private function buildMetadata(): Metadata
8481
$metadata->hasIdPMetadata = true;
8582
$metadata->ssoUrl = $this->getUrl($metadataConfiguration->ssoRoute);
8683

87-
if ($metadataConfiguration->idpCertificate &&
88-
$metadataConfiguration->idpCertificate !== '' &&
89-
$metadataConfiguration->idpCertificate !== '0'
90-
) {
84+
if ($metadataConfiguration->idpCertificate) {
9185
$certificate = $this->getCertificateData($metadataConfiguration->idpCertificate);
9286
} else {
9387
$certificate = $this->getCertificateData($metadataConfiguration->publicKey);

src/Monolog/SamlAuthenticationLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* Decorates a PSR logger and adds information pertaining to a SAML request procedure to each message's context.
2727
*
28-
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
28+
* @SuppressWarnings("PHPMD.TooManyPublicMethods")
2929
*/
3030
final class SamlAuthenticationLogger implements LoggerInterface
3131
{

src/SAML2/Attribute/AttributeDictionary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getAttributeDefinition(string $attributeName): AttributeDefiniti
107107

108108
public function findAttributeDefinitionByUrn(string $urn): ?AttributeDefinition
109109
{
110-
if (!is_string($urn) || $urn === '') {
110+
if ($urn === '') {
111111
throw InvalidArgumentException::invalidType('non-empty string', $urn, 'urn');
112112
}
113113

0 commit comments

Comments
 (0)