TypeMock::getGenerator()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
cc 4
nc 6
nop 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: danchukas
6
 * Date: 2017-07-18 08:46
7
 */
8
9
namespace DanchukAS\Mock;
10
11
/**
12
 * Class TypeMock
13
 * @package DanchukAS\Mock
14
 */
15
abstract class TypeMock
16
{
17
18
    protected static $optimalCount = 1;
19
20
    /**
21
     * @param int $count Кількість елементів для генератора
22
     * @return \array
23
     */
24
    public static function getGenerator($count = null)
25
    {
26
        if (null === $count) {
27
            $count = static::getOptimalCount();
28
        }
29
30
        $mock_list = [];
31
32
        $generator = static::getSample();
33
        foreach ($generator as $value) {
34
            $mock_list[] = $value;
35
            if (--$count <= 0) {
36
                break;
37
            }
38
        }
39
40
        return $mock_list;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mock_list returns the type array<mixed,mixed>|array which is incompatible with the documented return type array.
Loading history...
41
    }
42
43
    /**
44
     * @return int
45
     */
46
    protected static function getOptimalCount()
47
    {
48
        return static::$optimalCount;
49
    }
50
51
    /**
52
     * @return \Generator sample of type
53
     */
54
    abstract public static function getSample();
55
}