TransformerChain   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transform() 0 7 2
A addTransformerStep() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assertion\Transformer;
6
7
use SimpleSAML\SAML2\Configuration\IdentityProvider;
8
use SimpleSAML\SAML2\Configuration\IdentityProviderAware;
9
use SimpleSAML\SAML2\Configuration\ServiceProvider;
10
use SimpleSAML\SAML2\Configuration\ServiceProviderAware;
11
use SimpleSAML\SAML2\XML\saml\Assertion;
12
13
class TransformerChain implements TransformerInterface
14
{
15
    /** @var \SimpleSAML\SAML2\Assertion\Transformer\TransformerInterface[] */
16
    private $transformers = [];
17
18
19
    /**
20
     * Constructor for TransformerChain
21
     *
22
     * @param \SimpleSAML\SAML2\Configuration\IdentityProvider $identityProvider
23
     * @param \SimpleSAML\SAML2\Configuration\ServiceProvider $serviceProvider
24
     */
25
    public function __construct(
26
        private IdentityProvider $identityProvider,
27
        private ServiceProvider $serviceProvider,
28
    ) {
29
    }
30
31
32
    /**
33
     * @param \SimpleSAML\SAML2\Assertion\Transformer\TransformerInterface $transformer
34
     */
35
    public function addTransformerStep(TransformerInterface $transformer): void
36
    {
37
        if ($transformer instanceof IdentityProviderAware) {
38
            $transformer->setIdentityProvider($this->identityProvider);
39
        }
40
41
        if ($transformer instanceof ServiceProviderAware) {
42
            $transformer->setServiceProvider($this->serviceProvider);
43
        }
44
45
        $this->transformers[] = $transformer;
46
    }
47
48
49
    /**
50
     * @param \SimpleSAML\SAML2\XML\saml\Assertion $assertion
51
     *
52
     * @return \SimpleSAML\SAML2\XML\saml\Assertion
53
     */
54
    public function transform(Assertion $assertion): Assertion
55
    {
56
        foreach ($this->transformers as $transformer) {
57
            $assertion = $transformer->transform($assertion);
58
        }
59
60
        return $assertion;
61
    }
62
}
63