PluralFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 34
rs 10
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 14 5
A get() 0 4 1
1
<?php
2
3
namespace BZIon\Twig;
4
5
use Doctrine\Common\Inflector\Inflector;
6
7
class PluralFilter
8
{
9
    /**
10
     * Make sure that a number is accompanied with the appropriate grammatical
11
     * number
12
     *
13
     * @param number $number
14
     * @param string $singular The noun in its singular form
15
     * @param string|null $plural The noun in its plural form (calculated
16
     *                            automatically by default)
17
     * @param bool   $hideNumber Whether or not to hide the number from the return value
18
     *
19
     * @return string
20 1
     */
21
    public function __invoke($singular, $number = null, $plural = null, $hideNumber = null)
22 1
    {
23 1
        if ($number == 1) {
24
            return "1 $singular";
25
        }
26 1
27
        $plural = $plural ?: Inflector::pluralize($singular);
28 1
29 1
        if ($number === null || $hideNumber) {
30
            return $plural;
31
        }
32 1
33
        return "$number $plural";
34
    }
35 1
36
    public static function get()
37 1
    {
38
        return new \Twig_SimpleFilter('plural', new self());
39
    }
40
}
41