Completed
Pull Request — master (#3)
by Harry
03:17
created

CompressionFactoryTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 19.72 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 14
loc 71
wmc 10
lcom 1
cbo 2
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetCompressorForGzipReturnsGzip() 7 7 1
A testGetCompressorForZipReturnsZip() 7 7 1
A testGetCompressorForNoneWillThrowAnException() 0 5 1
A testGetDeCompressorForNoneWillThrowAnException() 0 5 1
A testGetCompressorForUnknownWillThrowAnException() 0 5 1
A testGetDeCompressorForUnknownWillThrowAnException() 0 5 1
A testGetCompressorForRandomWillThrowAnException() 0 5 1
A testGetDeCompressorForRandomWillThrowAnException() 0 5 1
A testIsCompression() 0 6 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
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Modify\Compress;
15
16
use Graze\DataFile\Modify\Compress\CompressionFactory;
17
use Graze\DataFile\Modify\Compress\Gzip;
18
use Graze\DataFile\Modify\Compress\Zip;
19
use Graze\DataFile\Modify\Exception\InvalidCompressionTypeException;
20
use Graze\DataFile\Test\TestCase;
21
22
class CompressionFactoryTest extends TestCase
23
{
24
    /**
25
     * @var CompressionFactory
26
     */
27
    private $factory;
28
29
    public function setUp()
30
    {
31
        $this->factory = new CompressionFactory();
32
    }
33
34 View Code Duplication
    public function testGetCompressorForGzipReturnsGzip()
0 ignored issues
show
Duplication introduced by
This method 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...
35
    {
36
        $object = $this->factory->getCompressor(Gzip::NAME);
37
        static::assertInstanceOf(Gzip::class, $object);
38
        $object = $this->factory->getDeCompressor(Gzip::NAME);
39
        static::assertInstanceOf(Gzip::class, $object);
40
    }
41
42 View Code Duplication
    public function testGetCompressorForZipReturnsZip()
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        $object = $this->factory->getCompressor(Zip::NAME);
45
        static::assertInstanceOf(Zip::class, $object);
46
        $object = $this->factory->getDeCompressor(Zip::NAME);
47
        static::assertInstanceOf(Zip::class, $object);
48
    }
49
50
    public function testGetCompressorForNoneWillThrowAnException()
51
    {
52
        $this->expectException(InvalidCompressionTypeException::class);
53
        $this->factory->getCompressor(CompressionFactory::TYPE_NONE);
54
    }
55
56
    public function testGetDeCompressorForNoneWillThrowAnException()
57
    {
58
        $this->expectException(InvalidCompressionTypeException::class);
59
        $this->factory->getDeCompressor(CompressionFactory::TYPE_NONE);
60
    }
61
62
    public function testGetCompressorForUnknownWillThrowAnException()
63
    {
64
        $this->expectException(InvalidCompressionTypeException::class);
65
        $this->factory->getCompressor(CompressionFactory::TYPE_UNKNOWN);
66
    }
67
68
    public function testGetDeCompressorForUnknownWillThrowAnException()
69
    {
70
        $this->expectException(InvalidCompressionTypeException::class);
71
        $this->factory->getDeCompressor(CompressionFactory::TYPE_UNKNOWN);
72
    }
73
74
    public function testGetCompressorForRandomWillThrowAnException()
75
    {
76
        $this->expectException(InvalidCompressionTypeException::class);
77
        $this->factory->getCompressor('random');
78
    }
79
80
    public function testGetDeCompressorForRandomWillThrowAnException()
81
    {
82
        $this->expectException(InvalidCompressionTypeException::class);
83
        $this->factory->getDeCompressor('random');
84
    }
85
86
    public function testIsCompression()
87
    {
88
        static::assertTrue($this->factory->isCompression(Gzip::NAME));
89
        static::assertTrue($this->factory->isCompression(Zip::NAME));
90
        static::assertFalse($this->factory->isCompression('lzop'));
91
    }
92
}
93