PageCanonicalService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 37
rs 10
c 4
b 0
f 0
ccs 0
cts 21
cp 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A generatePathForHomepage() 0 3 1
A generatePathForPage() 0 11 3
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