HeaderAttributesProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isEnabled() 0 4 1
A getAttributes() 0 8 2
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