Completed
Pull Request — master (#131)
by Arnaud
35:53
created

AdminHelper::setCurrent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Helper;
4
5
use LAG\AdminBundle\Admin\AdminInterface;
6
use LAG\AdminBundle\Exception\Exception;
7
8
class AdminHelper implements AdminHelperInterface
9
{
10
    private $frozen = false;
11
12
    /**
13
     * @var AdminInterface
14
     */
15
    private $admin;
16
17
    public function setCurrent(AdminInterface $admin): void
18
    {
19
        if ($this->frozen) {
20
            throw new Exception('The current admin cannot be set twice in a request');
21
        }
22
        $this->admin = $admin;
23
        $this->frozen = true;
24
    }
25
26
    public function getCurrent(): ?AdminInterface
27
    {
28
        return $this->admin;
29
    }
30
}
31