Passed
Push — master ( 962f84...b4b8c9 )
by
unknown
03:42 queued 15s
created

TwigReadingTimeExtension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Flynt\Utils;
4
5
use Twig_Extension;
6
use Twig_SimpleFilter;
7
8
class TwigReadingTimeExtension extends Twig_Extension
9
{
10
    public function getName()
11
    {
12
        return 'ReadingTime';
13
    }
14
15
    public function getFilters()
16
    {
17
        return [
18
            new Twig_SimpleFilter('readingtime', [$this, 'readingtimeFilter'])
19
        ];
20
    }
21
22
    public function readingtimeFilter($content)
23
    {
24
        $wordsPerMinute = 200;
25
        $words = str_word_count(strip_tags($content));
26
        $minutesToRead = floor($words / $wordsPerMinute);
27
        $min = ($minutesToRead < 1 ? '1' : $minutesToRead);
28
29
        return $min;
30
    }
31
}
32