ConditionsAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 42
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A doExecute() 0 15 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-IDP package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the GPL-3 license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Idp\Action\Assertion\Outbound;
13
14
use LightSaml\Action\Assertion\AbstractAssertionAction;
15
use LightSaml\Context\Profile\AssertionContext;
16
use LightSaml\Provider\TimeProvider\TimeProviderInterface;
17
use LightSaml\Model\Assertion\AudienceRestriction;
18
use LightSaml\Model\Assertion\Conditions;
19
use Psr\Log\LoggerInterface;
20
21
/**
22
 * Creates Conditions and AudienceRestriction.
23
 */
24
class ConditionsAction extends AbstractAssertionAction
25
{
26
    /** @var TimeProviderInterface */
27
    protected $timeProvider;
28
29
    /** @var int */
30
    protected $expirationSeconds;
31
32
    /**
33
     * @param LoggerInterface       $logger
34
     * @param TimeProviderInterface $timeProvider
35
     * @param int                   $expirationSeconds
36
     */
37
    public function __construct(LoggerInterface $logger, TimeProviderInterface $timeProvider, $expirationSeconds)
38
    {
39
        parent::__construct($logger);
40
41
        $this->expirationSeconds = $expirationSeconds;
42
        $this->timeProvider = $timeProvider;
43
    }
44
45
    /**
46
     * @param AssertionContext $context
47
     *
48
     * @return void
49
     */
50
    protected function doExecute(AssertionContext $context)
51
    {
52
        $partyEntityDescriptor = $context->getProfileContext()->getPartyEntityDescriptor();
53
54
        $conditions = new Conditions();
55
        $conditions->setNotBefore($this->timeProvider->getTimestamp());
56
        $conditions->setNotOnOrAfter($conditions->getNotBeforeTimestamp() + $this->expirationSeconds);
57
58
        $audienceRestriction = new AudienceRestriction(array(
59
            $partyEntityDescriptor->getEntityID(),
60
        ));
61
        $conditions->addItem($audienceRestriction);
62
63
        $context->getAssertion()->setConditions($conditions);
64
    }
65
}
66