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

Extension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 37
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 6 6 1
A size_format() 8 8 3
A getName() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}