Test Failed
Pull Request — master (#5)
by Alex
07:05
created

Between   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 31
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 22 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Query\Filter;
6
7
use Arp\LaminasDoctrine\Query\Constant\WhereType;
8
use Arp\LaminasDoctrine\Query\Exception\InvalidArgumentException;
9
use Arp\LaminasDoctrine\Query\Metadata\MetadataInterface;
10
use Arp\LaminasDoctrine\Query\QueryBuilderInterface;
11
use Doctrine\ORM\Query\Expr;
12
13
/**
14
 * @author  Alex Patterson <[email protected]>
15
 * @package Arp\LaminasDoctrine\Query\Filter
16
 */
17
final class Between extends AbstractFilter
18
{
19
    /**
20
     * @param QueryBuilderInterface $queryBuilder
21
     * @param MetadataInterface     $metadata
22
     * @param array                 $criteria
23
     *
24
     * @throws InvalidArgumentException
25
     */
26
    public function filter(QueryBuilderInterface $queryBuilder, MetadataInterface $metadata, array $criteria): void
27
    {
28
        $fieldName = $this->resolveFieldName($metadata, $criteria);
0 ignored issues
show
Bug introduced by
The call to Arp\LaminasDoctrine\Quer...ter::resolveFieldName() has too few arguments starting with key. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        /** @scrutinizer ignore-call */ 
29
        $fieldName = $this->resolveFieldName($metadata, $criteria);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
Are you sure the assignment to $fieldName is correct as $this->resolveFieldName($metadata, $criteria) targeting Arp\LaminasDoctrine\Quer...ter::resolveFieldName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
30
        $queryAlias = $criteria['alias'] ?? 'entity';
31
        $paramName = uniqid($queryAlias, false);
32
33
        $expression = $queryBuilder->expr()->between(
0 ignored issues
show
Bug introduced by
The call to Doctrine\ORM\Query\Expr::between() has too few arguments starting with val. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $expression = $queryBuilder->expr()->/** @scrutinizer ignore-call */ between(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
34
35
        );
0 ignored issues
show
Coding Style introduced by
The first argument in a multi-line function call must be on the line after the opening parenthesis
Loading history...
36
37
38
        if (!isset($criteria['where']) || WhereType::AND === $criteria['where']) {
39
            $queryBuilder->andWhere($expression);
40
        } else {
41
            $queryBuilder->orWhere($expression);
42
        }
43
44
        // Some comparisons will not require a value to be provided
45
        if (array_key_exists('value', $criteria)) {
46
            $value = $this->formatValue($metadata, $fieldName, $criteria['value'], $criteria['format'] ?? null);
0 ignored issues
show
Bug introduced by
$fieldName of type null is incompatible with the type string expected by parameter $fieldName of Arp\LaminasDoctrine\Quer...ctFilter::formatValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            $value = $this->formatValue($metadata, /** @scrutinizer ignore-type */ $fieldName, $criteria['value'], $criteria['format'] ?? null);
Loading history...
47
            $queryBuilder->setParameter($paramName, $value);
48
        }
49
    }
50
}
51