CallbackFilterTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 83
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilterClosureEmpty() 0 17 1
A testFilterClosureNotEmpty() 0 15 1
A testFilterMethodEmpty() 0 15 1
A testFilterMethodNotEmpty() 0 13 1
A customCallback() 0 4 1
A testFilterException() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Filter;
15
16
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery;
17
use Sonata\DoctrineMongoDBAdminBundle\Filter\CallbackFilter;
18
19
class CallbackFilterTest extends FilterWithQueryBuilderTest
20
{
21
    public function testFilterClosureEmpty()
22
    {
23
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
25
        $filter = new CallbackFilter();
26
        $filter->initialize('field_name', [
27
            'callback' => static function ($builder, $alias, $field, $value) {
0 ignored issues
show
Unused Code introduced by Andriy Rakhnin
The parameter $builder is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Andriy Rakhnin
The parameter $alias is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Andriy Rakhnin
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Andriy Rakhnin
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                return true;
29
            },
30
        ]);
31
32
        $filter->filter($builder, 'alias', 'field', false);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
        $filter->filter($builder, 'alias', 'field', 'scalarValue');
34
        $filter->filter($builder, 'alias', 'field', ['value' => '']);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
array('value' => '') is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36
        $this->assertFalse($filter->isActive());
37
    }
38
39
    public function testFilterClosureNotEmpty()
40
    {
41
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by Kévin Dunglas
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
43
        $filter = new CallbackFilter();
44
        $filter->initialize('field_name', [
45
            'callback' => static function ($builder, $alias, $field, $value) {
0 ignored issues
show
Unused Code introduced by Kévin Dunglas
The parameter $builder is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $alias is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
                return true;
47
            },
48
        ]);
49
50
        $filter->filter($builder, 'alias', 'field', ['value' => 'myValue']);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
array('value' => 'myValue') is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
52
        $this->assertTrue($filter->isActive());
53
    }
54
55
    public function testFilterMethodEmpty()
56
    {
57
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
59
        $filter = new CallbackFilter();
60
        $filter->initialize('field_name', [
61
            'callback' => [$this, 'customCallback'],
62
        ]);
63
64
        $filter->filter($builder, 'alias', 'field', false);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        $filter->filter($builder, 'alias', 'field', 'scalarValue');
66
        $filter->filter($builder, 'alias', 'field', ['value' => '']);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
array('value' => '') is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
68
        $this->assertFalse($filter->isActive());
69
    }
70
71
    public function testFilterMethodNotEmpty()
72
    {
73
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by Kévin Dunglas
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
75
        $filter = new CallbackFilter();
76
        $filter->initialize('field_name', [
77
            'callback' => [$this, 'customCallback'],
78
        ]);
79
80
        $filter->filter($builder, 'alias', 'field', ['value' => 'myValue']);
0 ignored issues
show
Documentation introduced by Andriy Rakhnin
array('value' => 'myValue') is of type array<string,string,{"value":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
82
        $this->assertTrue($filter->isActive());
83
    }
84
85
    public function customCallback($builder, $alias, $field, $value)
0 ignored issues
show
Unused Code introduced by Kévin Dunglas
The parameter $builder is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $alias is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Kévin Dunglas
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    {
87
        return true;
88
    }
89
90
    public function testFilterException()
91
    {
92
        $this->expectException(\RuntimeException::class);
93
94
        $builder = new ProxyQuery($this->getQueryBuilder());
0 ignored issues
show
Documentation introduced by Kévin Dunglas
$this->getQueryBuilder() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ODM\MongoDB\Query\Builder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
96
        $filter = new CallbackFilter();
97
        $filter->initialize('field_name', []);
98
99
        $filter->filter($builder, 'alias', 'field', 'myValue');
100
    }
101
}
102