Failed Conditions
Pull Request — master (#7885)
by Šimon
09:39
created

GetIterableTester::assertResultsAreTheSame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests;
6
7
use Doctrine\ORM\Query;
8
use PHPUnit\Framework\Assert;
9
use function array_values;
10
use function is_array;
11
use function iterator_to_array;
12
13
final class GetIterableTester
14
{
15
    public static function assertResultsAreTheSame(Query $query) : void
16
    {
17
        $result   = $query->getResult();
18
        $iterable = $query->getIterable();
19
20
        Assert::assertSame($result, self::iterableToArray($iterable));
21
    }
22
23
    /**
24
     * Copy the iterable into an array. If the iterable is already an array, return it.
25
     *
26
     * @param bool $use_keys [optional] Whether to use the iterator element keys as index.
27
     *
28
     * @return array
29
     */
30
    private static function iterableToArray(iterable $iterable, $use_keys = true) : array
31
    {
32
        if (is_array($iterable)) {
33
            return ($use_keys ? $iterable : array_values($iterable));
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
34
        }
35
36
        return iterator_to_array($iterable, $use_keys);
37
    }
38
}
39