Completed
Push — master ( f339fb...41f35e )
by Filipe
08:39
created

Text   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 46
ccs 21
cts 21
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
B getFilters() 0 27 1
1
<?php
2
3
/**
4
 * This file is part of slick/template package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Template\Extension;
11
12
use Slick\Template\Engine\Twig;
13
use Slick\Template\EngineExtensionInterface;
14
use Slick\Template\TemplateEngineInterface;
15
16
/**
17
 * Twig text utility extension for Slick/Template
18
 *
19
 * @package Slick\Template\Extension
20
 * @author  Filipe Silva <[email protected]>
21
 */
22
class Text extends AbstractTwigExtension implements EngineExtensionInterface
23
{
24
25
    /**
26
     * Returns the name of the extension.
27
     *
28
     * @return string The extension name
29
     */
30 2
    public function getName()
31
    {
32 2
        return 'Text utilities extension';
33
    }
34
35
    /**
36
     * Returns a list of filters
37
     *
38
     * @return array
39
     */
40 4
    public function getFilters()
41
    {
42
        return [
43 4
            new \Twig_SimpleFilter(
44 4
                'truncate',
45
                function ($value, $len=75, $ter='...', $preserve = false) {
46 2
                    return \Slick\Common\Utils\Text::truncate(
47 2
                        $value,
48 2
                        $len,
49 2
                        $ter,
50
                        $preserve
51 2
                    );
52
                }
53 4
            ),
54 4
            new \Twig_SimpleFilter(
55 4
                'wordwrap',
56 2
                function ($value, $length = 75, $break = "\n", $cut = false) {
57 2
                    return \Slick\Common\Utils\Text::wordwrap(
58 2
                        $value,
59 2
                        $length,
60 2
                        $break,
61
                        $cut
62 2
                    );
63
                }
64 4
            )
65 4
        ];
66
    }
67
}