Activator::activate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\EditInPlace;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Session\Session;
16
17
/**
18
 * Default Activator implementation.
19
 *
20
 * @author Damien Alexandre <[email protected]>
21
 */
22
final class Activator implements ActivatorInterface
23
{
24
    const KEY = 'translation_bundle.edit_in_place.enabled';
25
26
    /**
27
     * @var Session
28
     */
29
    private $session;
30
31
    public function __construct(Session $session)
32
    {
33
        $this->session = $session;
34
    }
35
36
    /**
37
     * Enable the Edit In Place mode.
38
     */
39
    public function activate(): void
40
    {
41
        $this->session->set(self::KEY, true);
42
    }
43
44
    /**
45
     * Disable the Edit In Place mode.
46
     */
47
    public function deactivate(): void
48
    {
49
        $this->session->remove(self::KEY);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function checkRequest(Request $request = null): bool
56
    {
57
        if (!$this->session->has(self::KEY)) {
58
            return false;
59
        }
60
61
        return $this->session->get(self::KEY, false);
62
    }
63
}
64