Code Duplication    Length = 37-37 lines in 2 locations

Twig/HumanReadableExtension.php 1 location

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

Twig/HumanReadableExtension/Extension.php 1 location

@@ 23-59 (lines=37) @@
20
 * Class HumanReadableExtension
21
 * @package phpFastCache\Bundle\Twig
22
 */
23
class Extension extends \Twig_Extension
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
}