Completed
Push — master ( cf207c...9dbd6f )
by Valery
08:47
created

AppExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A showPageNumber() 0 4 2
A __construct() 0 4 1
A getFilters() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Twig;
6
7
use Symfony\Contracts\Translation\TranslatorInterface;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFilter;
10
11
final class AppExtension extends AbstractExtension
12
{
13
    /**
14
     * @var TranslatorInterface
15
     */
16
    private $translator;
17
18
    public function __construct(TranslatorInterface $translator)
19
    {
20
        $this->translator = $translator;
21
    }
22
23
    public function getFilters()
24
    {
25
        return [
26
            new TwigFilter('page', [$this, 'showPageNumber']),
27
        ];
28
    }
29
30
    public function showPageNumber($number = 1): string
31
    {
32
        return ($number > 1) ? ' - '.$this->translator->trans('page').' '.$number : '';
33
    }
34
}
35