Completed
Push — master ( 7fe5eb...9bad48 )
by Beñat
08:54 queued 04:27
created

UserFakeData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 35.48 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 11
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ids() 0 4 1
A amount() 0 4 1
A userOfIndex() 11 11 3
A mod() 0 6 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
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\SharedKernel\Infrastructure\Persistence\Fake;
16
17
use Symfony\Component\Yaml\Yaml;
18
19
final class UserFakeData
20
{
21
    public function ids() : array
22
    {
23
        return Yaml::parse(file_get_contents(__DIR__ . '/Data/user_ids.yml'));
24
    }
25
26
    public function amount() : int
27
    {
28
        return count($this->ids());
29
    }
30
31 View Code Duplication
    public function userOfIndex(int $index, array $list = null) : string
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...
32
    {
33
        $list = null === $list ? $this->ids() : $list;
34
35
        $numberOfUserIds = count($list);
36
        $j = $this->mod($index, $numberOfUserIds - 1) > $numberOfUserIds
37
            ? 0
38
            : $this->mod(($numberOfUserIds - ($index - 1)), $numberOfUserIds);
39
40
        return $list[$j];
41
    }
42
43
    private function mod(int $first, int $second) : int
44
    {
45
        $result = $first % $second;
46
47
        return $result < 0 ? $result + $second : $result;
48
    }
49
}
50