Passed
Pull Request — master (#5678)
by Angel Fernando Quiroz
07:40
created

AccessUrlHelper::isMultipleEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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\AccessUrl;
10
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
11
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12
use Symfony\Component\Routing\RouterInterface;
13
14
class AccessUrlHelper
15
{
16
    public function __construct(
17
        private readonly AccessUrlRepository $accessUrlRepository,
18
        private readonly RouterInterface $router,
19
    ) {}
20
21
    public function getFirstAccessUrl(): AccessUrl
22
    {
23
        $urlId = $this->accessUrlRepository->getFirstId();
24
25
        return $this->accessUrlRepository->find($urlId);
26
    }
27
28
    public function getCurrent(): AccessUrl
29
    {
30
        static $accessUrl;
31
32
        if (!empty($accessUrl)) {
33
            return $accessUrl;
34
        }
35
36
        $url = $this->router->generate('index', [], UrlGeneratorInterface::ABSOLUTE_URL);
37
38
        /** @var AccessUrl $accessUrl */
39
        $accessUrl = $this->accessUrlRepository->findOneBy(['url' => $url]);
40
41
        if (!$accessUrl) {
0 ignored issues
show
introduced by
$accessUrl is of type Chamilo\CoreBundle\Entity\AccessUrl, thus it always evaluated to true.
Loading history...
42
            $accessUrl = $this->getFirstAccessUrl();
43
        }
44
45
        return $accessUrl;
46
    }
47
}
48