PageCanonicalService::generatePathForPage()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
ccs 0
cts 6
cp 0
crap 12
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