TwigReadingTimeExtension::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Flynt\Utils;
4
5
use Twig_Extension;
6
use Twig\TwigFilter;
7
8
class TwigReadingTimeExtension extends Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
class TwigReadingTimeExtension extends /** @scrutinizer ignore-deprecated */ Twig_Extension
Loading history...
9
{
10
    public function getName()
11
    {
12
        return 'ReadingTime';
13
    }
14
15
    public function getFilters()
16
    {
17
        return [
18
            new TwigFilter('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