HeaderAttributesProvider::isEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\Service;
4
5
use Symfony\Component\HttpFoundation\RequestStack;
6
7
class HeaderAttributesProvider implements AttributesInjectionProviderInterface
8
{
9
    /**
10
     * @var RequestStack
11
     */
12
    protected $requestStack;
13
14
    /**
15
     * @var bool
16
     */
17
    protected $enabled;
18
19
    /**
20
     * @param RequestStack $requestStack
21
     * @param bool         $enabled
22
     */
23
    public function __construct(RequestStack $requestStack, $enabled = false)
24
    {
25
        $this->requestStack = $requestStack;
26
        $this->enabled = $enabled;
27
    }
28
29
    /**
30
     * @return bool
31
     */
32
    public function isEnabled()
33
    {
34
        return $this->enabled;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getAttributes()
41
    {
42
        $attributes = $this->requestStack->getCurrentRequest()->headers->all();
43
        array_walk($attributes, function (&$value) {
44
            $value = (is_array($value) ? implode(';', $value) : $value);
45
        });
46
        return $attributes;
47
    }
48
}
49