Passed
Push — master ( d1c2a2...5885e4 )
by Angel Fernando Quiroz
17:30 queued 15s
created

CidReqHelper::getSessionEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\ServiceHelper;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\Session;
11
use Chamilo\CoreBundle\EventListener\CourseListener;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\RequestStack;
14
use Symfony\Component\HttpFoundation\Session\SessionInterface;
15
16
/**
17
 * @see CourseListener::onKernelRequest()
18
 */
19
class CidReqHelper
20
{
21
    public function __construct(
22
        private readonly RequestStack $requestStack,
23
    ) {}
24
25
    private function getRequest(): ?Request
26
    {
27
        return $this->requestStack->getCurrentRequest();
28
    }
29
30
    private function getSessionHandler(): SessionInterface
31
    {
32
        return $this->getRequest()->getSession();
33
    }
34
35
    public function getSessionId(): ?int
36
    {
37
        return $this->getSessionHandler()->get('sid');
38
    }
39
40
    public function getSessionEntity(): ?Session
41
    {
42
        return $this->getSessionHandler()->get('session');
43
    }
44
45
    public function getCourseId()
46
    {
47
        return $this->getSessionHandler()->get('cid');
48
    }
49
50
    public function getCourseEntity(): ?Course
51
    {
52
        return $this->getSessionHandler()->get('course');
53
    }
54
55
    public function getGroupId(): ?int
56
    {
57
        return $this->getSessionHandler()->get('gid');
58
    }
59
}
60