SelectOrUnionAll   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 21 6
1
<?php
2
3
namespace mav3rick177\RapidPagination\Base\Query;
4
5
use mav3rick177\RapidPagination\Base\ArrayCursor;
6
use mav3rick177\RapidPagination\Base\Contracts\Cursor;
7
8
/**
9
 * Class SelectOrUnionAll
10
 */
11
abstract class SelectOrUnionAll implements \IteratorAggregate
12
{
13
    /**
14
     * @param  Order[]                $orders
15
     * @param  Cursor|int[]|string[]  $cursor
16
     * @param  Limit                  $limit
17
     * @param  Direction              $direction
18
     * @param  bool                   $exclusive
19
     * @param  bool                   $seekable
20
     * @return Select|static|UnionAll
21
     */
22 17
    public static function create(array $orders, $cursor, Limit $limit, Direction $direction, $exclusive, $seekable)
23
    {
24 17
        $cursor = $cursor instanceof Cursor ? $cursor : new ArrayCursor($cursor);
25 17
        $mainQuery = new Select(
26 17
            $cursor->has() ? ConditionGroup::createMany($orders, $cursor, $direction, $exclusive) : [],
27 17
            $direction->backward()
28 6
                ? array_map(static function (Order $order) {
29 6
                    return $order->inverse();
30 6
                }, $orders)
31 17
                : $orders,
32
            $limit
33
        );
34
35 17
        if (!$cursor->has() || !$seekable) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cursor->has() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
36
            // We don't need UNION ALL and support query when cursor parameters are empty,
37
            // or it does not need to be seekable.
38 7
            return $mainQuery;
39
        }
40
41 10
        return new UnionAll($mainQuery);
42
    }
43
}
44