Completed
Push — master ( ce7b38...6ec792 )
by Peter
04:34
created

Bzip2Compressor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 0
dl 30
loc 30
ccs 0
cts 17
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B compress() 21 21 6

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
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace GpsLab\Component\Sitemap\Compressor;
10
11 View Code Duplication
class Bzip2Compressor implements CompressorInterface
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...
12
{
13
    /**
14
     * @param string $source
15
     * @param string $target
16
     *
17
     * @return bool
18
     */
19
    public function compress($source, $target = '')
20
    {
21
        $target = $target ?: $source.'.bz2';
22
        $rh = @fopen($source, 'rb');
23
        $bz = @bzopen($target, 'w9');
24
25
        if ($rh === false || $bz === false) {
26
            return false;
27
        }
28
29
        while (!feof($rh)) {
30
            if (bzwrite($bz, fread($rh, 1024)) === false) {
31
                return false;
32
            }
33
        }
34
35
        fclose($rh);
36
        bzclose($bz);
37
38
        return true;
39
    }
40
}
41