ResolveLogoutPartyAction::findParty()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 10
cp 0
cc 3
eloc 6
nc 3
nop 2
crap 12
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Logout 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\Logout\Action\Profile\Outbound\LogoutRequest;
13
14
use LightSaml\Action\Profile\AbstractProfileAction;
15
use LightSaml\Context\Profile\ProfileContext;
16
use LightSaml\Error\LightSamlContextException;
17
use LightSaml\Meta\TrustOptions\TrustOptions;
18
use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface;
19
use LightSaml\Store\TrustOptions\TrustOptionsStoreInterface;
20
21
class ResolveLogoutPartyAction extends AbstractProfileAction
22
{
23
    /** @var EntityDescriptorStoreInterface */
24
    private $idpEntityDescriptorStore;
25
26
    /** @var EntityDescriptorStoreInterface */
27
    private $spEntityDescriptorStore;
28
29
    /** @var TrustOptionsStoreInterface */
30
    protected $trustOptionsProvider;
31
32
    /**
33
     * @param EntityDescriptorStoreInterface $idpEntityDescriptorStore
34
     * @param EntityDescriptorStoreInterface $spEntityDescriptorStore
35
     * @param TrustOptionsStoreInterface     $trustOptionsProvider
36
     */
37
    public function __construct(
38
        EntityDescriptorStoreInterface $idpEntityDescriptorStore,
39
        EntityDescriptorStoreInterface $spEntityDescriptorStore,
40
        TrustOptionsStoreInterface $trustOptionsProvider
41
    ) {
42
        $this->idpEntityDescriptorStore = $idpEntityDescriptorStore;
43
        $this->spEntityDescriptorStore = $spEntityDescriptorStore;
44
        $this->trustOptionsProvider = $trustOptionsProvider;
45
    }
46
47
    /**
48
     * @param ProfileContext $context
49
     */
50
    protected function doExecute(ProfileContext $context)
51
    {
52
        $partyContext = $context->getPartyEntityContext();
53
54
        $partyEntityDescriptor = $this->getPartyEntityDescriptor($context);
55
        $partyContext
56
            ->setEntityId($partyEntityDescriptor->getEntityID())
57
            ->setEntityDescriptor($partyEntityDescriptor);
58
59
        $trustOptions = $this->trustOptionsProvider->get($partyContext->getEntityDescriptor()->getEntityID());
60
        if (null === $trustOptions) {
61
            $trustOptions = new TrustOptions();
62
        }
63
        $partyContext->setTrustOptions($trustOptions);
64
    }
65
66
    private function getPartyEntityDescriptor(ProfileContext $context)
67
    {
68
        $ssoSessionState = $context->getLogoutSsoSessionState();
69
        $ownEntityId = $context->getOwnEntityDescriptor()->getEntityID();
70
        $partyId = $ssoSessionState->getOtherPartyId($ownEntityId);
71
72
        $partyEntityDescriptor = $this->findParty($partyId, [$this->idpEntityDescriptorStore, $this->spEntityDescriptorStore]);
73
74
        if ($partyEntityDescriptor) {
75
            return $partyEntityDescriptor;
76
        }
77
78
        throw new LightSamlContextException($context, sprintf('Unknown party "%s"', $partyId));
79
    }
80
81
    /**
82
     * @param string                           $entityId
83
     * @param EntityDescriptorStoreInterface[] $entityDescriptorStores
84
     *
85
     * @return \LightSaml\Model\Metadata\EntityDescriptor|null
86
     */
87
    private function findParty($entityId, array $entityDescriptorStores)
88
    {
89
        foreach ($entityDescriptorStores as $entityDescriptorStore) {
90
            $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...
91
            if ($entityDescriptor) {
92
                return $entityDescriptor;
93
            }
94
        }
95
96
        return;
97
    }
98
}
99