Failed Conditions
Pull Request — master (#319)
by Guilherme
08:18
created

SupportExtensions::mask()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 3
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\SupportBundle\Twig;
12
13
use Twig\Extension\AbstractExtension;
14
use Twig\TwigFilter;
15
16
class SupportExtensions extends AbstractExtension
17
{
18 1
    public function getFilters()
19
    {
20
        return [
21 1
            new TwigFilter('support_mask', [$this, 'mask']),
22
        ];
23
    }
24
25 1
    public function mask($value, bool $mask = true, $hideLength = false)
26
    {
27 1
        if (!$mask) {
28 1
            return $value;
29
        }
30
31 1
        if (!$hideLength) {
32 1
            return preg_replace('/\w/', '*', $value);
33
        } else {
34 1
            return str_repeat('*', $hideLength);
35
        }
36
    }
37
}
38