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

UserFakeData::mod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
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