AttributeAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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\Model\Assertion\AttributeStatement;
17
use LightSaml\Provider\Attribute\AttributeValueProviderInterface;
18
use Psr\Log\LoggerInterface;
19
20
/**
21
 * Creates AttributeStatement and sets attribute values provided by given attribute value provider.
22
 */
23
class AttributeAction extends AbstractAssertionAction
24
{
25
    /** @var AttributeValueProviderInterface */
26
    protected $attributeValueProvider;
27
28
    /**
29
     * @param LoggerInterface                 $logger
30
     * @param AttributeValueProviderInterface $attributeValueProvider
31
     */
32
    public function __construct(LoggerInterface $logger, AttributeValueProviderInterface $attributeValueProvider)
33
    {
34
        parent::__construct($logger);
35
36
        $this->attributeValueProvider = $attributeValueProvider;
37
    }
38
39
    /**
40
     * @param AssertionContext $context
41
     *
42
     * @return void
43
     */
44
    protected function doExecute(AssertionContext $context)
45
    {
46
        $attributes = $this->attributeValueProvider->getValues($context);
47
        if ($attributes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $attributes of type LightSaml\Model\Assertion\Attribute[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
48
            $attributeStatement = new AttributeStatement();
49
            $context->getAssertion()->addItem($attributeStatement);
50
            foreach ($attributes as $attribute) {
51
                $attributeStatement->addAttribute($attribute);
52
            }
53
        }
54
    }
55
}
56