Failed Conditions
Branch master (01ba0d)
by Arnold
06:58 queued 01:45
created

ProvideIterablesTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\Tests;
6
7
trait ProvideIterablesTrait
8
{
9
    protected function generateAssoc(iterable $values): \Generator
10
    {
11
        foreach ($values as $key => $value) {
12
            yield $key => $value;
13
        }
14
    }
15
16
    protected function generateTricky(iterable $values): \Generator
17
    {
18
        foreach ($values as $value) {
19
            yield [] => $value;
20
        }
21
    }
22
23
    public function provideIterables(array $values, $tricky = false, $fixedArray = true)
24
    {
25
        $tests = [
26
            [$values, $values],
27
            [new \ArrayIterator($values), $values],
28
            [new \ArrayObject($values), $values],
29
            [$this->generateAssoc($values), $values]
30
        ];
31
32
        if ($fixedArray) {
33
            $tests[] = [\SplFixedArray::fromArray(array_values($values)), array_values($values)];
34
        }
35
36
        if ($tricky) {
37
            $tests[] = [$this->generateTricky($values), array_values($values)];
38
        }
39
40
        return $tests;
41
    }
42
}
43