Passed
Push — master ( 379797...6ccc0f )
by Saulius
02:01
created

HelpersTwigExtension::multiSplit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of the sauls/components-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Bundle\Components\Twig\Extension;
14
15
use function Sauls\Component\Helper\base64_url_decode;
16
use function Sauls\Component\Helper\base64_url_encode;
17
use function Sauls\Component\Helper\countdown;
18
use function Sauls\Component\Helper\elapsed_time;
19
use function Sauls\Component\Helper\explode_using_multi_delimiters;
20
use function Sauls\Component\Helper\string_camelize;
21
use function Sauls\Component\Helper\string_snakeify;
22
use Twig\Extension\AbstractExtension;
23
24
class HelpersTwigExtension extends AbstractExtension
25
{
26 7
    public function getFilters()
27
    {
28
        return [
29 7
            new \Twig_SimpleFilter('elapsed_time', [$this, 'elapsedTime']),
30 7
            new \Twig_SimpleFilter('countdown', [$this, 'countdown']),
31 7
            new \Twig_SimpleFilter('camelize', [$this, 'camelize']),
32 7
            new \Twig_SimpleFilter('snakeify', [$this, 'snakeify']),
33 7
            new \Twig_SimpleFilter('multi_split', [$this, 'multiSplit']),
34 7
            new \Twig_SimpleFilter('base64_url_encode', [$this, 'base64UrlEncode']),
35 7
            new \Twig_SimpleFilter('base64_url_decode', [$this, 'base64UrlDecode']),
36
        ];
37
    }
38
39
    /**
40
     * @throws \Exception
41
     */
42 1
    public function elapsedTime($date, array $labels = [], $format = ELAPSED_TIME_FORMAT_FULL): string
43
    {
44 1
        return elapsed_time($date, $labels, $format);
45
    }
46
47
    /**
48
     * @throws \Exception
49
     */
50 1
    public function countdown($dateFrom = 'now', $dateTo, string $format = '%s%02d:%02d:%02d'): string
51
    {
52 1
        return countdown($dateFrom, $dateTo, $format);
53
    }
54
55
    /**
56
     * @throws \Exception
57
     */
58 1
    public function camelize(string $value): string
59
    {
60 1
        return string_camelize($value);
61
    }
62
63
    /**
64
     * @throws \Exception
65
     */
66 1
    public function snakeify(string $value): string
67
    {
68 1
        return string_snakeify($value);
69
    }
70
71
    /**
72
     * @throws \Exception
73
     */
74 1
    public function multiSplit(string $value, array $delimiters = ['.']): array
75
    {
76 1
        return explode_using_multi_delimiters($delimiters, $value);
77
    }
78
79
    /**
80
     * @throws \Exception
81
     */
82 1
    public function base64UrlEncode(string $value): string
83
    {
84 1
        return base64_url_encode($value);
85
    }
86
87
    /**
88
     * @throws \Exception
89
     */
90 1
    public function base64UrlDecode(string $value): string
91
    {
92 1
        return base64_url_decode($value);
93
    }
94
}
95