NumberHumanizerExtension::getFilters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 53
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 53
cts 53
cp 1
rs 9.7251
c 0
b 0
f 0
cc 1
eloc 37
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace EmanueleMinotto\HumanizerBundle\Twig;
4
5
use Coduo\PHPHumanizer\NumberHumanizer;
6
use Twig_SimpleFilter;
7
8
/**
9
 * Twig extension used to map NumberHumanizer methods to Twig filters.
10
 *
11
 * @author Emanuele Minotto <[email protected]>
12
 */
13
class NumberHumanizerExtension extends AbstractHumanizerExtension
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 45
    public function getFilters()
19
    {
20
        return [
21 45
            new Twig_SimpleFilter(
22 45
                'ordinalize',
23 30
                function ($number) {
24 3
                    return NumberHumanizer::ordinalize(
25 2
                        $number,
26 3
                        $this->translator->getLocale()
27 1
                    );
28 30
                }
29 15
            ),
30 30
            new Twig_SimpleFilter('ordinal', function ($number) {
31 3
                return NumberHumanizer::ordinal(
32 2
                    $number,
33 3
                    $this->translator->getLocale()
34 1
                );
35 45
            }),
36 45
            new Twig_SimpleFilter(
37 45
                'binary_suffix',
38 30
                function ($number) {
39 3
                    return NumberHumanizer::binarySuffix(
40 2
                        $number,
41 3
                        $this->translator->getLocale()
42 1
                    );
43 30
                }
44 15
            ),
45 45
            new Twig_SimpleFilter(
46 45
                'precise_binary_suffix',
47 30
                function ($number, $precision) {
48 3
                    return NumberHumanizer::preciseBinarySuffix(
49 2
                        $number,
50 2
                        $precision,
51 3
                        $this->translator->getLocale()
52 1
                    );
53 30
                }
54 15
            ),
55 45
            new Twig_SimpleFilter(
56 45
                'metric_suffix',
57 31
                function ($number) {
58 3
                    return NumberHumanizer::metricSuffix(
59 2
                        $number,
60 3
                        $this->translator->getLocale()
61 1
                    );
62 30
                }
63 15
            ),
64 45
            new Twig_SimpleFilter(
65 45
                'to_roman',
66 45
                [NumberHumanizer::class, 'toRoman']
67 15
            ),
68 45
            new Twig_SimpleFilter(
69 45
                'from_roman',
70 45
                [NumberHumanizer::class, 'fromRoman']
71 15
            ),
72 15
        ];
73
    }
74
75 15
    public function getName()
76
    {
77 15
        return 'humanizer_number';
78
    }
79
}
80