StorageTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 34.57 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 28
loc 81
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
createStorage() 0 1 ?
A testGetSet() 0 13 1
A testHas() 13 13 1
A testRemove() 15 15 1
A testClear() 0 17 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 the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Storage\Tests\Units;
13
14
use Cubiche\Core\Storage\StorageInterface;
15
use Cubiche\Core\Storage\Tests\Fixtures\User;
16
17
/**
18
 * StorageTestCase class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
abstract class StorageTestCase extends TestCase
23
{
24
    /**
25
     * @return StorageInterface
26
     */
27
    abstract protected function createStorage();
28
29
    /**
30
     * Test get method.
31
     */
32
    public function testGetSet()
33
    {
34
        $this
35
            ->given($storage = $this->createStorage())
36
            ->and($user = new User('Ivan', 36, '[email protected]'))
37
            ->when($storage->set('foo', $user))
38
            ->then()
39
                ->object($storage->get('foo'))
40
                    ->isEqualTo($user)
41
                ->integer($storage->get('baz', 15))
42
                    ->isEqualTo(15)
43
        ;
44
    }
45
46
    /**
47
     * Test has method.
48
     */
49 View Code Duplication
    public function testHas()
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...
50
    {
51
        $this
52
            ->given($storage = $this->createStorage())
53
            ->and($user = new User('Ivan', 36, '[email protected]'))
54
            ->when($storage->set('foo', $user))
55
            ->then()
56
                ->boolean($storage->has('foo'))
57
                    ->isTrue()
58
                ->boolean($storage->has('baz'))
59
                    ->isFalse()
60
        ;
61
    }
62
63
    /**
64
     * Test remove method.
65
     */
66 View Code Duplication
    public function testRemove()
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...
67
    {
68
        $this
69
            ->given($storage = $this->createStorage())
70
            ->when(
71
                $storage->set('a', 'red'),
72
                $storage->set('b', 'blue')
73
            )
74
            ->then()
75
                ->boolean($storage->remove('a'))
76
                    ->isTrue()
77
                ->boolean($storage->remove('c'))
78
                    ->isFalse()
79
        ;
80
    }
81
82
    /**
83
     * Test clear method.
84
     */
85
    public function testClear()
86
    {
87
        $this
88
            ->given($storage = $this->createStorage())
89
            ->when(
90
                $storage->set('a', 'red'),
91
                $storage->set('b', 'blue')
92
            )
93
            ->then()
94
                ->array($storage->keys())
95
                    ->isNotEmpty()
96
                ->when($storage->clear())
97
                ->then()
98
                    ->array($storage->keys())
99
                        ->isEmpty()
100
        ;
101
    }
102
}
103