IsLoggedDataSource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLoggedStatus() 0 10 3
A getLoggedStatusFormParams() 0 13 1
1
<?php
2
3
namespace Victoire\Bundle\CriteriaBundle\DataSource;
4
5
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
6
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
7
8
class IsLoggedDataSource
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
9
{
10
    /**
11
     * @var AuthorizationChecker
12
     */
13
    private $authorizationChecker;
14
15
    /**
16
     * IsLoggedDataSource constructor.
17
     *
18
     * @param AuthorizationChecker $authorizationChecker
19
     */
20
    public function __construct(AuthorizationChecker $authorizationChecker)
21
    {
22
        $this->authorizationChecker = $authorizationChecker;
23
    }
24
25
    /**
26
     * Check actual status of current user return true if logged false if not.
27
     *
28
     * @return bool
29
     */
30
    public function getLoggedStatus()
31
    {
32
        if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
33
            return true;
34
        } elseif ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getLoggedStatusFormParams()
45
    {
46
        return [
47
            'type'    => ChoiceType::class,
48
            'options' => [
49
                'choices' => [
50
                    true  => 'victoire_criteria.request_user.is.connected.criteria.label',
51
                    false => 'victoire_criteria.request_user.is.not.connected.criteria.label',
52
                ],
53
                'multiple' => false,
54
            ],
55
        ];
56
    }
57
}
58