ArrayStorage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 43.48 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 10
loc 23
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A remember() 10 10 2

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 Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Storage\Drivers;
11
12
use Railt\Io\Readable;
13
use Railt\Storage\Storage;
14
15
/**
16
 * Class ArrayStorage
17
 */
18
class ArrayStorage implements Storage
19
{
20
    /**
21
     * @var array|object[]
22
     */
23
    private $storage = [];
24
25
    /**
26
     * @param Readable $readable
27
     * @param \Closure $then
28
     * @return object|mixed
29
     */
30 View Code Duplication
    public function remember(Readable $readable, \Closure $then)
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...
31
    {
32
        $key = $readable->getHash();
33
34
        if (! \array_key_exists($key, $this->storage)) {
35
            $this->storage[$key] = $then($readable);
36
        }
37
38
        return $this->storage[$key];
39
    }
40
}
41