RendererTest::testRender()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 43
Code Lines 32

Duplication

Lines 43
Ratio 100 %

Importance

Changes 0
Metric Value
dl 43
loc 43
rs 8.439
c 0
b 0
f 0
cc 5
eloc 32
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\GridBundle\Tests\Renderer;
13
14
use Lug\Bundle\GridBundle\Renderer\Renderer;
15
use Lug\Bundle\GridBundle\View\GridViewInterface;
16
use Lug\Component\Grid\Action\ActionRendererInterface;
17
use Lug\Component\Grid\Column\ColumnRendererInterface;
18
use Lug\Component\Grid\Model\ActionInterface;
19
use Lug\Component\Grid\Model\ColumnInterface;
20
use Lug\Component\Grid\Model\GridInterface;
21
use Lug\Component\Grid\Renderer\RendererInterface;
22
use Lug\Component\Grid\Sort\SorterInterface;
23
use Lug\Component\Grid\Sort\SorterRendererInterface;
24
25
/**
26
 * @author GeLo <[email protected]>
27
 */
28
class RendererTest extends \PHPUnit_Framework_TestCase
29
{
30
    /**
31
     * @var Renderer
32
     */
33
    private $renderer;
34
35
    /**
36
     * @var \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment
37
     */
38
    private $twig;
39
40
    /**
41
     * @var \PHPUnit_Framework_MockObject_MockObject|ActionRendererInterface
42
     */
43
    private $actionRenderer;
44
45
    /**
46
     * @var \PHPUnit_Framework_MockObject_MockObject|ColumnRendererInterface
47
     */
48
    private $columnRenderer;
49
50
    /**
51
     * @var \PHPUnit_Framework_MockObject_MockObject|SorterRendererInterface
52
     */
53
    private $sorterRenderer;
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function setUp()
59
    {
60
        $this->twig = $this->createTwigEnvironmentMock();
61
        $this->actionRenderer = $this->createActionRendererMock();
62
        $this->columnRenderer = $this->createColumnRendererMock();
63
        $this->sorterRenderer = $this->createSorterRendererMock();
64
65
        $this->renderer = new Renderer(
66
            $this->twig,
67
            $this->actionRenderer,
68
            $this->columnRenderer,
69
            $this->sorterRenderer
70
        );
71
    }
72
73
    public function testInheritance()
74
    {
75
        $this->assertInstanceOf(RendererInterface::class, $this->renderer);
76
    }
77
78
    /**
79
     * @dataProvider renderProvider
80
     */
81 View Code Duplication
    public function testRender($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $template = 'grid';
84
85
        if ($rendererTemplate !== null) {
86
            $this->renderer = new Renderer(
87
                $this->twig,
88
                $this->actionRenderer,
89
                $this->columnRenderer,
90
                $this->sorterRenderer,
91
                [$template => $rendererTemplate]
92
            );
93
        }
94
95
        $view = $this->createGridViewMock();
96
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
97
            ->expects($this->once())
98
            ->method('getDefinition')
99
            ->will($this->returnValue($grid = $this->createGridMock()));
100
101
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
102
            ->expects($this->once())
103
            ->method('hasOption')
104
            ->with($this->identicalTo($option = $template.'_template'))
105
            ->will($this->returnValue($gridTemplate !== null));
106
107
        $grid
108
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
109
            ->method('getOption')
110
            ->with($this->identicalTo($option))
111
            ->will($this->returnValue($gridTemplate));
112
113
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
114
            ->expects($this->once())
115
            ->method('render')
116
            ->with(
117
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
118
                $this->identicalTo(['grid' => $view])
119
            )
120
            ->will($this->returnValue($result = 'result'));
121
122
        $this->assertSame($result, $this->renderer->render($view));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 95 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Renderer\Renderer::render() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
    }
124
125
    /**
126
     * @dataProvider renderProvider
127
     */
128 View Code Duplication
    public function testRenderFilters($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $template = 'filters';
131
132
        if ($rendererTemplate !== null) {
133
            $this->renderer = new Renderer(
134
                $this->twig,
135
                $this->actionRenderer,
136
                $this->columnRenderer,
137
                $this->sorterRenderer,
138
                [$template => $rendererTemplate]
139
            );
140
        }
141
142
        $view = $this->createGridViewMock();
143
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
144
            ->expects($this->once())
145
            ->method('getDefinition')
146
            ->will($this->returnValue($grid = $this->createGridMock()));
147
148
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
149
            ->expects($this->once())
150
            ->method('hasOption')
151
            ->with($this->identicalTo($option = $template.'_template'))
152
            ->will($this->returnValue($gridTemplate !== null));
153
154
        $grid
155
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
156
            ->method('getOption')
157
            ->with($this->identicalTo($option))
158
            ->will($this->returnValue($gridTemplate));
159
160
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
161
            ->expects($this->once())
162
            ->method('render')
163
            ->with(
164
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
165
                $this->identicalTo(['grid' => $view])
166
            )
167
            ->will($this->returnValue($result = 'result'));
168
169
        $this->assertSame($result, $this->renderer->renderFilters($view));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 142 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...nderer::renderFilters() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
170
    }
171
172
    /**
173
     * @dataProvider renderProvider
174
     */
175 View Code Duplication
    public function testRenderGrid($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        $template = 'body';
178
179
        if ($rendererTemplate !== null) {
180
            $this->renderer = new Renderer(
181
                $this->twig,
182
                $this->actionRenderer,
183
                $this->columnRenderer,
184
                $this->sorterRenderer,
185
                [$template => $rendererTemplate]
186
            );
187
        }
188
189
        $view = $this->createGridViewMock();
190
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
191
            ->expects($this->once())
192
            ->method('getDefinition')
193
            ->will($this->returnValue($grid = $this->createGridMock()));
194
195
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
196
            ->expects($this->once())
197
            ->method('hasOption')
198
            ->with($this->identicalTo($option = $template.'_template'))
199
            ->will($this->returnValue($gridTemplate !== null));
200
201
        $grid
202
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
203
            ->method('getOption')
204
            ->with($this->identicalTo($option))
205
            ->will($this->returnValue($gridTemplate));
206
207
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
208
            ->expects($this->once())
209
            ->method('render')
210
            ->with(
211
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
212
                $this->identicalTo(['grid' => $view])
213
            )
214
            ->will($this->returnValue($result = 'result'));
215
216
        $this->assertSame($result, $this->renderer->renderGrid($view));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 189 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...\Renderer::renderGrid() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
217
    }
218
219
    /**
220
     * @dataProvider renderProvider
221
     */
222 View Code Duplication
    public function testRenderColumn($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
223
    {
224
        $template = 'column';
225
226
        if ($rendererTemplate !== null) {
227
            $this->renderer = new Renderer(
228
                $this->twig,
229
                $this->actionRenderer,
230
                $this->columnRenderer,
231
                $this->sorterRenderer,
232
                [$template => $rendererTemplate]
233
            );
234
        }
235
236
        $view = $this->createGridViewMock();
237
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
238
            ->expects($this->once())
239
            ->method('getDefinition')
240
            ->will($this->returnValue($grid = $this->createGridMock()));
241
242
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
243
            ->expects($this->once())
244
            ->method('hasOption')
245
            ->with($this->identicalTo($option = $template.'_template'))
246
            ->will($this->returnValue($gridTemplate !== null));
247
248
        $grid
249
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
250
            ->method('getOption')
251
            ->with($this->identicalTo($option))
252
            ->will($this->returnValue($gridTemplate));
253
254
        $this->columnRenderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Column\ColumnRendererInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
255
            ->expects($this->once())
256
            ->method('render')
257
            ->with(
258
                $this->identicalTo($view),
259
                $this->identicalTo($column = $this->createColumnMock()),
260
                $this->identicalTo($data = new \stdClass())
261
            )
262
            ->will($this->returnValue($value = 'value'));
263
264
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
265
            ->expects($this->once())
266
            ->method('render')
267
            ->with(
268
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
269
                $this->identicalTo([
270
                    'column' => $column,
271
                    'data'   => $data,
272
                    'value'  => $value,
273
                    'grid'   => $view,
274
                ])
275
            )
276
            ->will($this->returnValue($result = 'result'));
277
278
        $this->assertSame($result, $this->renderer->renderColumn($view, $column, $data));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 236 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...enderer::renderColumn() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $column defined by $this->createColumnMock() on line 259 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...enderer::renderColumn() does only seem to accept object<Lug\Component\Grid\Model\ColumnInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
279
    }
280
281
    /**
282
     * @dataProvider renderProvider
283
     */
284 View Code Duplication
    public function testRenderColumnSortings($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
285
    {
286
        $template = 'column_sortings';
287
288
        if ($rendererTemplate !== null) {
289
            $this->renderer = new Renderer(
290
                $this->twig,
291
                $this->actionRenderer,
292
                $this->columnRenderer,
293
                $this->sorterRenderer,
294
                [$template => $rendererTemplate]
295
            );
296
        }
297
298
        $view = $this->createGridViewMock();
299
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
300
            ->expects($this->once())
301
            ->method('getDefinition')
302
            ->will($this->returnValue($grid = $this->createGridMock()));
303
304
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
305
            ->expects($this->once())
306
            ->method('hasOption')
307
            ->with($this->identicalTo($option = $template.'_template'))
308
            ->will($this->returnValue($gridTemplate !== null));
309
310
        $grid
311
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
312
            ->method('getOption')
313
            ->with($this->identicalTo($option))
314
            ->will($this->returnValue($gridTemplate));
315
316
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
317
            ->expects($this->once())
318
            ->method('render')
319
            ->with(
320
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
321
                $this->identicalTo([
322
                    'column' => $column = $this->createColumnMock(),
323
                    'grid'   => $view,
324
                ])
325
            )
326
            ->will($this->returnValue($result = 'result'));
327
328
        $this->assertSame($result, $this->renderer->renderColumnSortings($view, $column));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 298 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...:renderColumnSortings() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $column defined by $this->createColumnMock() on line 322 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...:renderColumnSortings() does only seem to accept object<Lug\Component\Grid\Model\ColumnInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
329
    }
330
331
    /**
332
     * @dataProvider renderProvider
333
     */
334
    public function testRenderColumnSorting($gridTemplate = null, $rendererTemplate = null)
335
    {
336
        $template = 'column_sorting';
337
338
        if ($rendererTemplate !== null) {
339
            $this->renderer = new Renderer(
340
                $this->twig,
341
                $this->actionRenderer,
342
                $this->columnRenderer,
343
                $this->sorterRenderer,
344
                [$template => $rendererTemplate]
345
            );
346
        }
347
348
        $view = $this->createGridViewMock();
349
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
350
            ->expects($this->once())
351
            ->method('getDefinition')
352
            ->will($this->returnValue($grid = $this->createGridMock()));
353
354
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
355
            ->expects($this->once())
356
            ->method('hasOption')
357
            ->with($this->identicalTo($option = $template.'_template'))
358
            ->will($this->returnValue($gridTemplate !== null));
359
360
        $grid
361
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
362
            ->method('getOption')
363
            ->with($this->identicalTo($option))
364
            ->will($this->returnValue($gridTemplate));
365
366
        $this->sorterRenderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Sort\SorterRendererInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
367
            ->expects($this->once())
368
            ->method('render')
369
            ->with(
370
                $this->identicalTo($view),
371
                $this->identicalTo($column = $this->createColumnMock()),
372
                $this->identicalTo($sorting = SorterInterface::ASC)
373
            )
374
            ->will($this->returnValue($value = 'value'));
375
376
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
377
            ->expects($this->once())
378
            ->method('render')
379
            ->with(
380
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
381
                $this->identicalTo([
382
                    'column'  => $column,
383
                    'sorting' => $sorting,
384
                    'label'   => 'lug.sorting.'.strtolower($sorting),
385
                    'value'   => $value,
386
                    'grid'    => $view,
387
                ])
388
            )
389
            ->will($this->returnValue($result = 'result'));
390
391
        $this->assertSame($result, $this->renderer->renderColumnSorting($view, $column, $sorting));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 348 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...::renderColumnSorting() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $column defined by $this->createColumnMock() on line 371 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...::renderColumnSorting() does only seem to accept object<Lug\Component\Grid\Model\ColumnInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
392
    }
393
394
    /**
395
     * @dataProvider renderProvider
396
     */
397 View Code Duplication
    public function testRenderColumnActions($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
    {
399
        $template = 'column_actions';
400
401
        if ($rendererTemplate !== null) {
402
            $this->renderer = new Renderer(
403
                $this->twig,
404
                $this->actionRenderer,
405
                $this->columnRenderer,
406
                $this->sorterRenderer,
407
                [$template => $rendererTemplate]
408
            );
409
        }
410
411
        $view = $this->createGridViewMock();
412
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
413
            ->expects($this->once())
414
            ->method('getDefinition')
415
            ->will($this->returnValue($grid = $this->createGridMock()));
416
417
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
418
            ->expects($this->once())
419
            ->method('hasOption')
420
            ->with($this->identicalTo($option = $template.'_template'))
421
            ->will($this->returnValue($gridTemplate !== null));
422
423
        $grid
424
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
425
            ->method('getOption')
426
            ->with($this->identicalTo($option))
427
            ->will($this->returnValue($gridTemplate));
428
429
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
430
            ->expects($this->once())
431
            ->method('render')
432
            ->with(
433
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
434
                $this->identicalTo([
435
                    'data' => $data = new \stdClass(),
436
                    'grid' => $view,
437
                ])
438
            )
439
            ->will($this->returnValue($result = 'result'));
440
441
        $this->assertSame($result, $this->renderer->renderColumnActions($view, $data));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 411 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...::renderColumnActions() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
442
    }
443
444
    /**
445
     * @dataProvider renderProvider
446
     */
447 View Code Duplication
    public function testRenderColumnAction($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
448
    {
449
        $template = 'column_action';
450
451
        if ($rendererTemplate !== null) {
452
            $this->renderer = new Renderer(
453
                $this->twig,
454
                $this->actionRenderer,
455
                $this->columnRenderer,
456
                $this->sorterRenderer,
457
                [$template => $rendererTemplate]
458
            );
459
        }
460
461
        $view = $this->createGridViewMock();
462
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
463
            ->expects($this->once())
464
            ->method('getDefinition')
465
            ->will($this->returnValue($grid = $this->createGridMock()));
466
467
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
468
            ->expects($this->once())
469
            ->method('hasOption')
470
            ->with($this->identicalTo($option = $template.'_template'))
471
            ->will($this->returnValue($gridTemplate !== null));
472
473
        $grid
474
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
475
            ->method('getOption')
476
            ->with($this->identicalTo($option))
477
            ->will($this->returnValue($gridTemplate));
478
479
        $this->actionRenderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Action\ActionRendererInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
480
            ->expects($this->once())
481
            ->method('render')
482
            ->with(
483
                $this->identicalTo($view),
484
                $this->identicalTo($action = $this->createActionMock()),
485
                $this->identicalTo($data = new \stdClass())
486
            )
487
            ->will($this->returnValue($value = 'value'));
488
489
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
490
            ->expects($this->once())
491
            ->method('render')
492
            ->with(
493
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
494
                $this->identicalTo([
495
                    'action' => $action,
496
                    'data'   => $data,
497
                    'value'  => $value,
498
                    'grid'   => $view,
499
                ])
500
            )
501
            ->will($this->returnValue($result = 'result'));
502
503
        $this->assertSame($result, $this->renderer->renderColumnAction($view, $action, $data));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 461 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...r::renderColumnAction() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $action defined by $this->createActionMock() on line 484 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...r::renderColumnAction() does only seem to accept object<Lug\Component\Grid\Model\ActionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
504
    }
505
506
    /**
507
     * @dataProvider renderProvider
508
     */
509 View Code Duplication
    public function testRenderGlobalActions($gridTemplate = null, $rendererTemplate = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
510
    {
511
        $template = 'global_actions';
512
513
        if ($rendererTemplate !== null) {
514
            $this->renderer = new Renderer(
515
                $this->twig,
516
                $this->actionRenderer,
517
                $this->columnRenderer,
518
                $this->sorterRenderer,
519
                [$template => $rendererTemplate]
520
            );
521
        }
522
523
        $view = $this->createGridViewMock();
524
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
525
            ->expects($this->once())
526
            ->method('getDefinition')
527
            ->will($this->returnValue($grid = $this->createGridMock()));
528
529
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
530
            ->expects($this->once())
531
            ->method('hasOption')
532
            ->with($this->identicalTo($option = $template.'_template'))
533
            ->will($this->returnValue($gridTemplate !== null));
534
535
        $grid
536
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
537
            ->method('getOption')
538
            ->with($this->identicalTo($option))
539
            ->will($this->returnValue($gridTemplate));
540
541
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
542
            ->expects($this->once())
543
            ->method('render')
544
            ->with(
545
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
546
                $this->identicalTo(['grid' => $view])
547
            )
548
            ->will($this->returnValue($result = 'result'));
549
550
        $this->assertSame($result, $this->renderer->renderGlobalActions($view));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 523 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...::renderGlobalActions() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
551
    }
552
553
    /**
554
     * @dataProvider renderProvider
555
     */
556
    public function testRenderGlobalAction($gridTemplate = null, $rendererTemplate = null)
557
    {
558
        $template = 'global_action';
559
560
        if ($rendererTemplate !== null) {
561
            $this->renderer = new Renderer(
562
                $this->twig,
563
                $this->actionRenderer,
564
                $this->columnRenderer,
565
                $this->sorterRenderer,
566
                [$template => $rendererTemplate]
567
            );
568
        }
569
570
        $view = $this->createGridViewMock();
571
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
572
            ->expects($this->once())
573
            ->method('getDefinition')
574
            ->will($this->returnValue($grid = $this->createGridMock()));
575
576
        $grid
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Model\GridInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
577
            ->expects($this->once())
578
            ->method('hasOption')
579
            ->with($this->identicalTo($option = $template.'_template'))
580
            ->will($this->returnValue($gridTemplate !== null));
581
582
        $grid
583
            ->expects($gridTemplate !== null ? $this->once() : $this->never())
584
            ->method('getOption')
585
            ->with($this->identicalTo($option))
586
            ->will($this->returnValue($gridTemplate));
587
588
        $this->actionRenderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Grid\Action\ActionRendererInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
589
            ->expects($this->once())
590
            ->method('render')
591
            ->with(
592
                $this->identicalTo($view),
593
                $this->identicalTo($action = $this->createActionMock()),
594
                $this->isNull()
595
            )
596
            ->will($this->returnValue($value = 'value'));
597
598
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Twig_Environment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
599
            ->expects($this->once())
600
            ->method('render')
601
            ->with(
602
                $this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/'.$template.'.html.twig')),
603
                $this->identicalTo([
604
                    'action' => $action,
605
                    'value'  => $value,
606
                    'grid'   => $view,
607
                ])
608
            )
609
            ->will($this->returnValue($result = 'result'));
610
611
        $this->assertSame($result, $this->renderer->renderGlobalAction($view, $action));
0 ignored issues
show
Bug introduced by
It seems like $view defined by $this->createGridViewMock() on line 570 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...r::renderGlobalAction() does only seem to accept object<Lug\Component\Grid\View\GridViewInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $action defined by $this->createActionMock() on line 593 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\GridBundle\Re...r::renderGlobalAction() does only seem to accept object<Lug\Component\Grid\Model\ActionInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
612
    }
613
614
    /**
615
     * @return mixed[]
616
     */
617
    public function renderProvider()
618
    {
619
        return [
620
            'default_template'  => [],
621
            'grid_template'     => ['grid_template'],
622
            'renderer_template' => [null, 'grid_template'],
623
        ];
624
    }
625
626
    /**
627
     * @return \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment
628
     */
629
    public function createTwigEnvironmentMock()
630
    {
631
        return $this->createMock(\Twig_Environment::class);
632
    }
633
634
    /**
635
     * @return \PHPUnit_Framework_MockObject_MockObject|ActionRendererInterface
636
     */
637
    private function createActionRendererMock()
638
    {
639
        return $this->createMock(ActionRendererInterface::class);
640
    }
641
642
    /**
643
     * @return \PHPUnit_Framework_MockObject_MockObject|ColumnRendererInterface
644
     */
645
    private function createColumnRendererMock()
646
    {
647
        return $this->createMock(ColumnRendererInterface::class);
648
    }
649
650
    /**
651
     * @return \PHPUnit_Framework_MockObject_MockObject|SorterRendererInterface
652
     */
653
    private function createSorterRendererMock()
654
    {
655
        return $this->createMock(SorterRendererInterface::class);
656
    }
657
658
    /**
659
     * @return \PHPUnit_Framework_MockObject_MockObject|GridViewInterface
660
     */
661
    private function createGridViewMock()
662
    {
663
        return $this->createMock(GridViewInterface::class);
664
    }
665
666
    /**
667
     * @return \PHPUnit_Framework_MockObject_MockObject|GridInterface
668
     */
669
    private function createGridMock()
670
    {
671
        return $this->createMock(GridInterface::class);
672
    }
673
674
    /**
675
     * @return \PHPUnit_Framework_MockObject_MockObject|ActionInterface
676
     */
677
    private function createActionMock()
678
    {
679
        return $this->createMock(ActionInterface::class);
680
    }
681
682
    /**
683
     * @return \PHPUnit_Framework_MockObject_MockObject|ColumnInterface
684
     */
685
    private function createColumnMock()
686
    {
687
        return $this->createMock(ColumnInterface::class);
688
    }
689
}
690