ArrayGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 52
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 6 1
A generateArray() 0 16 3
generateRandomInt() 0 1 ?
1
<?php
2
3
namespace PragmaRX\Random\Generators;
4
5
trait ArrayGenerator
6
{
7
    protected $array = false;
8
9
    protected $items = [];
10
11
    protected $count = 1;
12
13
    /**
14
     * Set the array items count.
15
     *
16
     * @param $count
17
     * @return $this
18
     */
19 1
    public function count($count)
20
    {
21 1
        $this->count = $count;
22
23 1
        return $this;
24
    }
25
26
    /**
27
     * Generate random array elements.
28
     *
29
     * @return array
30
     */
31 1
    protected function generateArray()
32
    {
33 1
        $result = [];
34
35 1
        $last = count($this->items)-1;
36
37 1
        for ($counter = 1; $counter <= $this->count; $counter++) {
38 1
            $result[] = $this->items[$this->generateRandomInt(0, $last)];
39
        }
40
41 1
        if ($this->count == 1) {
42 1
            return $result[0];
43
        }
44
45 1
        return $result;
46
    }
47
48
    /**
49
     * Generate a random integer.
50
     *
51
     * @param int $start
52
     * @param int $end
53
     * @return int
54
     */
55
    abstract protected function generateRandomInt($start, $end);
56
}
57