Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

UtilitiesTwigExtension::slugify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Kunstmaan\UtilitiesBundle\Twig;
4
5
use Kunstmaan\UtilitiesBundle\Helper\SlugifierInterface;
6
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFilter;
8
9
/**
10
 * @final since 5.4
11
 */
12
class UtilitiesTwigExtension extends AbstractExtension
13
{
14
    /**
15
     * @var SlugifierInterface
16
     */
17
    private $slugifier;
18
19
    /**
20
     * @param $slugifier
21
     */
22
    public function __construct($slugifier)
23
    {
24
        $this->slugifier = $slugifier;
25
    }
26
27
    /**
28
     * Returns a list of filters.
29
     *
30
     * @return array An array of filters
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use TwigFilter[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
31
     */
32
    public function getFilters()
33
    {
34
        return [
35
            new TwigFilter('slugify', [$this, 'slugify']),
36
        ];
37
    }
38
39
    /**
40
     * @param string $text
41
     *
42
     * @return string
43
     */
44
    public function slugify($text)
45
    {
46
        return $this->slugifier->slugify($text);
47
    }
48
}
49