Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

CipherTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 7
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 3 1
A testEncryptAndDecrypt() 7 7 1
A testException() 0 5 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
namespace Tests\Kunstmaan\UtilitiesBundle\Helper\Cipher;
4
5
use Kunstmaan\UtilitiesBundle\Helper\Cipher\Cipher;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * CipherTest
10
 */
11
class CipherTest extends TestCase
12
{
13
    const SECRET = 'secret';
14
    const CONTENT = 'This is a random sentence which will be encrypted and then decrypted!';
15
16
    /**
17
     * @var Cipher
18
     */
19
    protected $cipher;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     *
25
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\Cipher::__construct
26
     */
27
    protected function setUp()
28
    {
29
        $this->cipher = new Cipher(self::SECRET);
30
    }
31
32
    /**
33
     * Tears down the fixture, for example, closes a network connection.
34
     * This method is called after a test is executed.
35
     */
36
    protected function tearDown()
37
    {
38
    }
39
40
    /**
41
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\Cipher::encrypt
42
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\Cipher::decrypt
43
     */
44 View Code Duplication
    public function testEncryptAndDecrypt()
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...
45
    {
46
        $encryptedValue = $this->cipher->encrypt(self::CONTENT);
47
        $this->assertNotEquals(self::CONTENT, $encryptedValue);
48
        $decryptedValue = $this->cipher->decrypt($encryptedValue);
49
        $this->assertEquals($decryptedValue, self::CONTENT);
50
    }
51
52
    public function testException()
53
    {
54
        $this->expectException(\Exception::class);
55
        new Cipher('');
56
    }
57
}
58