Completed
Push — master ( bf69c3...92abdd )
by Milos
03:34
created

ResolveLogoutPartyAction::doExecute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 6
1
<?php
2
3
namespace LightSaml\Logout\Action\Profile\Outbound\LogoutRequest;
4
5
use LightSaml\Action\Profile\AbstractProfileAction;
6
use LightSaml\Context\Profile\ProfileContext;
7
use LightSaml\Error\LightSamlContextException;
8
use LightSaml\Error\LightSamlProfileException;
9
use LightSaml\Meta\TrustOptions\TrustOptions;
10
use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface;
11
use LightSaml\Store\TrustOptions\TrustOptionsStoreInterface;
12
13
class ResolveLogoutPartyAction extends AbstractProfileAction
14
{
15
    /** @var EntityDescriptorStoreInterface */
16
    private $idpEntityDescriptorStore;
17
18
    /** @var EntityDescriptorStoreInterface */
19
    private $spEntityDescriptorStore;
20
21
    /** @var  TrustOptionsStoreInterface */
22
    protected $trustOptionsProvider;
23
24
    /**
25
     * @param EntityDescriptorStoreInterface $idpEntityDescriptorStore
26
     * @param EntityDescriptorStoreInterface $spEntityDescriptorStore
27
     * @param TrustOptionsStoreInterface     $trustOptionsProvider
28
     */
29
    public function __construct(
30
        EntityDescriptorStoreInterface $idpEntityDescriptorStore,
31
        EntityDescriptorStoreInterface $spEntityDescriptorStore,
32
        TrustOptionsStoreInterface $trustOptionsProvider
33
    ) {
34
        $this->idpEntityDescriptorStore = $idpEntityDescriptorStore;
35
        $this->spEntityDescriptorStore = $spEntityDescriptorStore;
36
        $this->trustOptionsProvider = $trustOptionsProvider;
37
    }
38
39
    /**
40
     * @param ProfileContext $context
41
     */
42
    protected function doExecute(ProfileContext $context)
43
    {
44
        $partyContext = $context->getPartyEntityContext();
45
46
        $partyEntityDescriptor = $this->getPartyEntityDescriptor($context);
47
        $partyContext
48
            ->setEntityId($partyEntityDescriptor->getEntityID())
49
            ->setEntityDescriptor($partyEntityDescriptor);
50
51
        $trustOptions = $this->trustOptionsProvider->get($partyContext->getEntityDescriptor()->getEntityID());
52
        if (null === $trustOptions) {
53
            $trustOptions = new TrustOptions();
54
        }
55
        $partyContext->setTrustOptions($trustOptions);
56
    }
57
58
    private function getPartyEntityDescriptor(ProfileContext $context)
59
    {
60
        $ssoSessionState = $context->getLogoutSsoSessionState();
61
        $ownEntityId = $context->getOwnEntityDescriptor()->getEntityID();
62
        $partyId = $ssoSessionState->getOtherPartyId($ownEntityId);
63
64
        $partyEntityDescriptor = $this->findParty($partyId, [$this->idpEntityDescriptorStore, $this->spEntityDescriptorStore]);
65
66
        if ($partyEntityDescriptor) {
67
            return $partyEntityDescriptor;
68
        }
69
70
        throw new LightSamlContextException($context, sprintf('Unknown party "%s"', $partyId));
71
    }
72
73
    /**
74
     * @param string                           $entityId
75
     * @param EntityDescriptorStoreInterface[] $entityDescriptorStores
76
     *
77
     * @return \LightSaml\Model\Metadata\EntityDescriptor|null
78
     */
79
    private function findParty($entityId, array $entityDescriptorStores)
80
    {
81
        foreach ($entityDescriptorStores as $entityDescriptorStore) {
82
            $entityDescriptor = $entityDescriptorStore->get($entityId);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $entityDescriptor is correct as $entityDescriptorStore->get($entityId) (which targets LightSaml\Store\EntityDe...orStoreInterface::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
83
            if ($entityDescriptor) {
84
                return $entityDescriptor;
85
            }
86
        }
87
88
        return null;
89
    }
90
}
91