Completed
Push — master ( c8fd93...a9ab00 )
by Georges
01:49
created

Extension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Georges.L (Geolim4)  <[email protected]>
11
 * @author PastisD https://github.com/PastisD
12
 * @author Alexander (asm89) <[email protected]>
13
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
14
 *
15
 */
16
17
namespace phpFastCache\Bundle\Twig\HumanReadableExtension;
18
19
/**
20
 * Class HumanReadableExtension
21
 * @package phpFastCache\Bundle\Twig
22
 */
23 View Code Duplication
class Extension extends \Twig_Extension
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * @return array
27
     */
28
    public function getFilters()
29
    {
30
        return array(
31
            new \Twig_SimpleFilter('sizeFormat', [$this, 'size_format']),
32
        );
33
    }
34
    /**
35
     * @param int $bytes Bytes/Octets
36
     * @param int $decimals Number for decimals to return
37
     * @param bool $octetFormat Use Octet notation instead of Bytes
38
     *
39
     * @return string
40
     */
41
    public function size_format($bytes, $decimals = 2, $octetFormat = false)
42
    {
43
        $bytes = (int) $bytes;
44
        $sz     = 'BKMGTP';
45
        $factor = floor(( strlen($bytes) - 1 ) / 3);
46
47
        return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)).@$sz[ $factor ].( $factor ? ($octetFormat ? 'O' : 'B') : '' );
48
    }
49
50
    /**
51
     * Extension name
52
     *
53
     * @return string
54
     */
55
    public function getName()
56
    {
57
        return 'human_readable_extension';
58
    }
59
}