diff --git a/phpstan.neon b/phpstan.neon index 1efea22..1d6a617 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: - level: 7 + level: 8 paths: - src tmpDir: build/phpstan \ No newline at end of file diff --git a/src/Federation/Factories/TrustChainFactory.php b/src/Federation/Factories/TrustChainFactory.php index f360f02..108f316 100644 --- a/src/Federation/Factories/TrustChainFactory.php +++ b/src/Federation/Factories/TrustChainFactory.php @@ -5,6 +5,7 @@ namespace SimpleSAML\OpenID\Federation\Factories; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; +use SimpleSAML\OpenID\Exceptions\TrustChainException; use SimpleSAML\OpenID\Federation\EntityStatement; use SimpleSAML\OpenID\Federation\MetadataPolicyApplicator; use SimpleSAML\OpenID\Federation\MetadataPolicyResolver; @@ -35,6 +36,12 @@ public function empty(): TrustChain */ public function fromStatements(EntityStatement ...$statements): TrustChain { + if (count($statements) < 3) { + throw new TrustChainException( + sprintf('TrustChain must have at least 3 statements, %s given.', count($statements)), + ); + } + $trustChain = $this->empty(); // First item should be the leaf configuration. @@ -46,7 +53,10 @@ public function fromStatements(EntityStatement ...$statements): TrustChain } // Last item should be trust anchor configuration. - $trustChain->addTrustAnchor(array_shift($statements)); + ($trustAnchorStatement = array_shift($statements)) || throw new TrustChainException( + 'No Trust Anchor statement present.', + ); + $trustChain->addTrustAnchor($trustAnchorStatement); return $trustChain; }