Completed
Pull Request — master (#366)
by Beñat
14:32
created

FakeDataCapabilities::amount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
trait FakeDataCapabilities
20
{
21
    abstract protected function type() : string;
22
23
    abstract protected function dataDir() : string;
24
25
    public function ids() : array
26
    {
27
        return Yaml::parse(
28
            file_get_contents(
29
                $this->dataDir() . '/' . $this->type() . '_ids.yml'
30
            )
31
        );
32
    }
33
34
    public function amount() : int
35
    {
36
        return count($this->ids());
37
    }
38
39 View Code Duplication
    public function dataOfIndex(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...
40
    {
41
        $list = null === $list ? $this->ids() : $list;
42
43
        $numberOfUserIds = count($list);
44
        $j = $this->mod($index, $numberOfUserIds - 1) > $numberOfUserIds
45
            ? 0
46
            : $this->mod(($numberOfUserIds - ($index - 1)), $numberOfUserIds);
47
48
        return $list[$j];
49
    }
50
51
    private function mod(int $first, int $second) : int
52
    {
53
        $result = $first % $second;
54
55
        return $result < 0 ? $result + $second : $result;
56
    }
57
}
58