PageCanonicalService::generatePathForHomepage()   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 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 2
b 0
f 0
1
<?php
2
3
namespace PiedWeb\CMSBundle\Service;
4
5
use Symfony\Component\Routing\Router;
6
7
class PageCanonicalService
8
{
9
    protected $router;
10
    protected $defaultLocaleWithoutPrefix;
11
    protected $defaultLocale;
12
    protected $locale;
13
    protected $params;
14
15
    public function __construct(
16
        Router $router,
17
        bool $defaultLocaleWithoutPrefix = false,
18
        ?string $defaultLocale = null
19
    ) {
20
        $this->router = $router;
21
        $this->defaultLocaleWithoutPrefix = $defaultLocaleWithoutPrefix;
22
        $this->defaultLocale = $defaultLocale;
23
    }
24
25
    public function generatePathForHomepage()
26
    {
27
        return $this->router->generate('piedweb_cms_page', ['slug' => '']);
28
    }
29
30
    /**
31
     * @var string Permit to generate a link for another language than the current request
32
     */
33
    public function generatePathForPage(?string $slug)
34
    {
35
        if (null === $slug) {
36
            return;
37
        }
38
39
        if ('' === $slug) {
40
            return $this->generatePathForHomepage();
41
        }
42
43
        return $this->router->generate('piedweb_cms_page', ['slug' => $slug]);
44
    }
45
}
46