Completed
Pull Request — master (#732)
by 12345
03:41
created

testAlters100QualityIfNotSetOnApplyFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 39

Duplication

Lines 57
Ratio 100 %
Metric Value
dl 57
loc 57
rs 9.6818
cc 1
eloc 39
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Liip\ImagineBundle\Tests\Filter;
4
5
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
6
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
7
use Liip\ImagineBundle\Model\Binary;
8
use Liip\ImagineBundle\Tests\AbstractTest;
9
10
/**
11
 * @covers Liip\ImagineBundle\Imagine\Filter\FilterManager
12
 */
13
class FilterManagerTest extends AbstractTest
14
{
15
    public function testThrowsIfNoLoadersAddedForFilterOnApplyFilter()
16
    {
17
        $config = $this->createFilterConfigurationMock();
18
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
19
            ->expects($this->atLeastOnce())
20
            ->method('get')
21
            ->with('thumbnail')
22
            ->will($this->returnValue(array(
23
                'filters' => array(
24
                    'thumbnail' => array(
25
                        'size' => array(180, 180),
26
                        'mode' => 'outbound',
27
                    ),
28
                ),
29
                'post_processors' => array(),
30
            )))
31
        ;
32
33
        $binary = new Binary('aContent', 'image/png', 'png');
34
35
        $filterManager = new FilterManager(
36
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 17 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
37
            $this->createImagineMock(),
38
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
39
        );
40
41
        $this->setExpectedException('InvalidArgumentException', 'Could not find filter loader for "thumbnail" filter type');
42
        $filterManager->applyFilter($binary, 'thumbnail');
43
    }
44
45 View Code Duplication
    public function testReturnFilteredBinaryWithExpectedContentOnApplyFilter()
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...
46
    {
47
        $originalContent = 'aOriginalContent';
48
        $expectedFilteredContent = 'theFilteredContent';
49
50
        $binary = new Binary($originalContent, 'image/png', 'png');
51
52
        $thumbConfig = array(
53
            'size' => array(180, 180),
54
            'mode' => 'outbound',
55
        );
56
57
        $config = $this->createFilterConfigurationMock();
58
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
59
            ->expects($this->atLeastOnce())
60
            ->method('get')
61
            ->with('thumbnail')
62
            ->will($this->returnValue(array(
63
                'filters' => array(
64
                    'thumbnail' => $thumbConfig,
65
                ),
66
                'post_processors' => array(),
67
            )))
68
        ;
69
70
        $image = $this->getMockImage();
71
        $image
72
            ->expects($this->once())
73
            ->method('get')
74
            ->will($this->returnValue($expectedFilteredContent))
75
        ;
76
77
        $imagine = $this->createImagineMock();
78
        $imagine
79
            ->expects($this->once())
80
            ->method('load')
81
            ->with($originalContent)
82
            ->will($this->returnValue($image))
83
        ;
84
85
        $loader = $this->getMockLoader();
86
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
87
            ->expects($this->once())
88
            ->method('load')
89
            ->with($this->identicalTo($image), $thumbConfig)
90
            ->will($this->returnArgument(0))
91
        ;
92
93
        $filterManager = new FilterManager(
94
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 57 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
95
            $imagine,
96
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
97
        );
98
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 85 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
99
100
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
101
102
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
103
        $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent());
104
    }
105
106 View Code Duplication
    public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApplyFilter()
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...
107
    {
108
        $originalContent = 'aOriginalContent';
109
        $expectedFormat = 'png';
110
111
        $binary = new Binary($originalContent, 'image/png', $expectedFormat);
112
113
        $thumbConfig = array(
114
            'size' => array(180, 180),
115
            'mode' => 'outbound',
116
        );
117
118
        $config = $this->createFilterConfigurationMock();
119
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
120
            ->expects($this->atLeastOnce())
121
            ->method('get')
122
            ->with('thumbnail')
123
            ->will($this->returnValue(array(
124
                'filters' => array(
125
                    'thumbnail' => $thumbConfig,
126
                ),
127
                'post_processors' => array(),
128
            )))
129
        ;
130
131
        $image = $this->getMockImage();
132
        $image
133
            ->expects($this->once())
134
            ->method('get')
135
            ->will($this->returnValue('aFilteredContent'))
136
        ;
137
138
        $imagine = $this->createImagineMock();
139
        $imagine
140
            ->expects($this->once())
141
            ->method('load')
142
            ->will($this->returnValue($image))
143
        ;
144
145
        $loader = $this->getMockLoader();
146
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
147
            ->expects($this->once())
148
            ->method('load')
149
            ->with($this->identicalTo($image), $thumbConfig)
150
            ->will($this->returnArgument(0))
151
        ;
152
153
        $filterManager = new FilterManager(
154
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 118 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
155
            $imagine,
156
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
157
        );
158
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 145 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
159
160
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
161
162
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
163
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
164
    }
165
166 View Code Duplication
    public function testReturnFilteredBinaryWithCustomFormatIfSetOnApplyFilter()
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...
167
    {
168
        $originalContent = 'aOriginalContent';
169
        $originalFormat = 'png';
170
        $expectedFormat = 'jpg';
171
172
        $binary = new Binary($originalContent, 'image/png', $originalFormat);
173
174
        $thumbConfig = array(
175
            'size' => array(180, 180),
176
            'mode' => 'outbound',
177
        );
178
179
        $config = $this->createFilterConfigurationMock();
180
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
181
            ->expects($this->atLeastOnce())
182
            ->method('get')
183
            ->with('thumbnail')
184
            ->will($this->returnValue(array(
185
                'format' => $expectedFormat,
186
                'filters' => array(
187
                    'thumbnail' => $thumbConfig,
188
                ),
189
                'post_processors' => array(),
190
            )))
191
        ;
192
193
        $image = $this->getMockImage();
194
        $image
195
            ->expects($this->once())
196
            ->method('get')
197
            ->will($this->returnValue('aFilteredContent'))
198
        ;
199
200
        $imagine = $this->createImagineMock();
201
        $imagine
202
            ->expects($this->once())
203
            ->method('load')
204
            ->will($this->returnValue($image))
205
        ;
206
207
        $loader = $this->getMockLoader();
208
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
209
            ->expects($this->once())
210
            ->method('load')
211
            ->with($this->identicalTo($image), $thumbConfig)
212
            ->will($this->returnArgument(0))
213
        ;
214
215
        $filterManager = new FilterManager(
216
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 179 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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
            $imagine,
218
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
219
        );
220
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 207 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
221
222
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
223
224
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
225
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
226
    }
227
228
    public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApplyFilter()
229
    {
230
        $originalContent = 'aOriginalContent';
231
        $expectedMimeType = 'image/png';
232
233
        $binary = new Binary($originalContent, $expectedMimeType, 'png');
234
235
        $thumbConfig = array(
236
            'size' => array(180, 180),
237
            'mode' => 'outbound',
238
        );
239
240
        $config = $this->createFilterConfigurationMock();
241
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
242
            ->expects($this->atLeastOnce())
243
            ->method('get')
244
            ->with('thumbnail')
245
            ->will($this->returnValue(array(
246
                'filters' => array(
247
                    'thumbnail' => $thumbConfig,
248
                ),
249
                'post_processors' => array(),
250
            )))
251
        ;
252
253
        $image = $this->getMockImage();
254
        $image
255
            ->expects($this->once())
256
            ->method('get')
257
            ->will($this->returnValue('aFilteredContent'))
258
        ;
259
260
        $imagine = $this->createImagineMock();
261
        $imagine
262
            ->expects($this->once())
263
            ->method('load')
264
            ->will($this->returnValue($image))
265
        ;
266
267
        $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
268
        $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Binary\MimeTypeGuesserInterface.

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...
269
            ->expects($this->never())
270
            ->method('guess')
271
        ;
272
273
        $loader = $this->getMockLoader();
274
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
275
            ->expects($this->once())
276
            ->method('load')
277
            ->with($this->identicalTo($image), $thumbConfig)
278
            ->will($this->returnArgument(0))
279
        ;
280
281
        $filterManager = new FilterManager(
282
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 240 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
283
            $imagine,
284
            $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeGuesser defined by $this->getMockMimeTypeGuesser() on line 267 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, 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...
285
        );
286
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 273 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
287
288
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
289
290
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
291
        $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType());
292
    }
293
294
    public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApplyFilter()
295
    {
296
        $originalContent = 'aOriginalContent';
297
        $originalMimeType = 'image/png';
298
        $expectedContent = 'aFilteredContent';
299
        $expectedMimeType = 'image/jpeg';
300
301
        $binary = new Binary($originalContent, $originalMimeType, 'png');
302
303
        $thumbConfig = array(
304
            'size' => array(180, 180),
305
            'mode' => 'outbound',
306
        );
307
308
        $config = $this->createFilterConfigurationMock();
309
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
310
            ->expects($this->atLeastOnce())
311
            ->method('get')
312
            ->with('thumbnail')
313
            ->will($this->returnValue(array(
314
                'format' => 'jpg',
315
                'filters' => array(
316
                    'thumbnail' => $thumbConfig,
317
                ),
318
                'post_processors' => array(),
319
            )))
320
        ;
321
322
        $image = $this->getMockImage();
323
        $image
324
            ->expects($this->once())
325
            ->method('get')
326
            ->will($this->returnValue($expectedContent))
327
        ;
328
329
        $imagine = $this->createImagineMock();
330
        $imagine
331
            ->expects($this->once())
332
            ->method('load')
333
            ->will($this->returnValue($image))
334
        ;
335
336
        $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
337
        $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Binary\MimeTypeGuesserInterface.

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...
338
            ->expects($this->once())
339
            ->method('guess')
340
            ->with($expectedContent)
341
            ->will($this->returnValue($expectedMimeType))
342
        ;
343
344
        $loader = $this->getMockLoader();
345
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
346
            ->expects($this->once())
347
            ->method('load')
348
            ->with($this->identicalTo($image), $thumbConfig)
349
            ->will($this->returnArgument(0))
350
        ;
351
352
        $filterManager = new FilterManager(
353
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 308 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
354
            $imagine,
355
            $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeGuesser defined by $this->getMockMimeTypeGuesser() on line 336 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, 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...
356
        );
357
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 344 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
358
359
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
360
361
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
362
        $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType());
363
    }
364
365 View Code Duplication
    public function testAltersQualityOnApplyFilter()
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...
366
    {
367
        $originalContent = 'aOriginalContent';
368
        $expectedQuality = 80;
369
370
        $binary = new Binary($originalContent, 'image/png', 'png');
371
372
        $thumbConfig = array(
373
            'size' => array(180, 180),
374
            'mode' => 'outbound',
375
        );
376
377
        $config = $this->createFilterConfigurationMock();
378
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
379
            ->expects($this->atLeastOnce())
380
            ->method('get')
381
            ->with('thumbnail')
382
            ->will($this->returnValue(array(
383
                'quality' => $expectedQuality,
384
                'filters' => array(
385
                    'thumbnail' => $thumbConfig,
386
                ),
387
                'post_processors' => array(),
388
            )))
389
        ;
390
391
        $image = $this->getMockImage();
392
        $image
393
            ->expects($this->once())
394
            ->method('get')
395
            ->with('png', array('quality' => $expectedQuality))
396
            ->will($this->returnValue('aFilteredContent'))
397
        ;
398
399
        $imagine = $this->createImagineMock();
400
        $imagine
401
            ->expects($this->once())
402
            ->method('load')
403
            ->will($this->returnValue($image))
404
        ;
405
406
        $loader = $this->getMockLoader();
407
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
408
            ->expects($this->once())
409
            ->method('load')
410
            ->with($this->identicalTo($image), $thumbConfig)
411
            ->will($this->returnArgument(0))
412
        ;
413
414
        $filterManager = new FilterManager(
415
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 377 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
416
            $imagine,
417
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
418
        );
419
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 406 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
420
421
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail'));
422
    }
423
424 View Code Duplication
    public function testAlters100QualityIfNotSetOnApplyFilter()
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...
425
    {
426
        $originalContent = 'aOriginalContent';
427
        $expectedQuality = 100;
428
429
        $binary = new Binary($originalContent, 'image/png', 'png');
430
431
        $thumbConfig = array(
432
            'size' => array(180, 180),
433
            'mode' => 'outbound',
434
        );
435
436
        $config = $this->createFilterConfigurationMock();
437
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
438
            ->expects($this->atLeastOnce())
439
            ->method('get')
440
            ->with('thumbnail')
441
            ->will($this->returnValue(array(
442
                'filters' => array(
443
                    'thumbnail' => $thumbConfig,
444
                ),
445
                'post_processors' => array(),
446
            )))
447
        ;
448
449
        $image = $this->getMockImage();
450
        $image
451
            ->expects($this->once())
452
            ->method('get')
453
            ->with('png', array('quality' => $expectedQuality))
454
            ->will($this->returnValue('aFilteredContent'))
455
        ;
456
457
        $imagine = $this->createImagineMock();
458
        $imagine
459
            ->expects($this->once())
460
            ->method('load')
461
            ->will($this->returnValue($image))
462
        ;
463
464
        $loader = $this->getMockLoader();
465
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
466
            ->expects($this->once())
467
            ->method('load')
468
            ->with($this->identicalTo($image), $thumbConfig)
469
            ->will($this->returnArgument(0))
470
        ;
471
472
        $filterManager = new FilterManager(
473
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 436 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
474
            $imagine,
475
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
476
        );
477
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 464 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
478
479
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail'));
480
    }
481
482
    public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilter()
483
    {
484
        $binary = new Binary('aContent', 'image/png', 'png');
485
486
        $runtimeConfig = array(
487
            'filters' => array(
488
                'thumbnail' => array(
489
                    'size' => array(100, 100),
490
                ),
491
            ),
492
            'post_processors' => array(),
493
        );
494
495
        $thumbConfig = array(
496
            'size' => array(180, 180),
497
            'mode' => 'outbound',
498
        );
499
500
        $thumbMergedConfig = array(
501
            'size' => array(100, 100),
502
            'mode' => 'outbound',
503
        );
504
505
        $config = $this->createFilterConfigurationMock();
506
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
507
            ->expects($this->atLeastOnce())
508
            ->method('get')
509
            ->with('thumbnail')
510
            ->will($this->returnValue(array(
511
                'filters' => array(
512
                    'thumbnail' => $thumbConfig,
513
                ),
514
                'post_processors' => array(),
515
            )))
516
        ;
517
518
        $image = $this->getMockImage();
519
        $image
520
            ->expects($this->once())
521
            ->method('get')
522
            ->will($this->returnValue('aFilteredContent'))
523
        ;
524
525
        $imagine = $this->createImagineMock();
526
        $imagine
527
            ->expects($this->once())
528
            ->method('load')
529
            ->will($this->returnValue($image))
530
        ;
531
532
        $loader = $this->getMockLoader();
533
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
534
            ->expects($this->once())
535
            ->method('load')
536
            ->with($this->identicalTo($image), $thumbMergedConfig)
537
            ->will($this->returnArgument(0))
538
        ;
539
540
        $filterManager = new FilterManager(
541
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 505 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
542
            $imagine,
543
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
544
        );
545
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 532 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
546
547
        $this->assertInstanceOf(
548
            'Liip\ImagineBundle\Model\Binary',
549
            $filterManager->applyFilter($binary, 'thumbnail', $runtimeConfig)
550
        );
551
    }
552
553
    public function testThrowsIfNoLoadersAddedForFilterOnApply()
554
    {
555
        $binary = new Binary('aContent', 'image/png', 'png');
556
557
        $filterManager = new FilterManager(
558
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
559
            $this->createImagineMock(),
560
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
561
        );
562
563
        $this->setExpectedException('InvalidArgumentException', 'Could not find filter loader for "thumbnail" filter type');
564
        $filterManager->apply($binary, array(
565
            'filters' => array(
566
                'thumbnail' => array(
567
                    'size' => array(180, 180),
568
                    'mode' => 'outbound',
569
                ),
570
            ),
571
        ));
572
    }
573
574 View Code Duplication
    public function testReturnFilteredBinaryWithExpectedContentOnApply()
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...
575
    {
576
        $originalContent = 'aOriginalContent';
577
        $expectedFilteredContent = 'theFilteredContent';
578
579
        $binary = new Binary($originalContent, 'image/png', 'png');
580
581
        $thumbConfig = array(
582
            'size' => array(180, 180),
583
            'mode' => 'outbound',
584
        );
585
586
        $image = $this->getMockImage();
587
        $image
588
            ->expects($this->once())
589
            ->method('get')
590
            ->will($this->returnValue($expectedFilteredContent))
591
        ;
592
593
        $imagineMock = $this->createImagineMock();
594
        $imagineMock
595
            ->expects($this->once())
596
            ->method('load')
597
            ->with($originalContent)
598
            ->will($this->returnValue($image))
599
        ;
600
601
        $loader = $this->getMockLoader();
602
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
603
            ->expects($this->once())
604
            ->method('load')
605
            ->with($this->identicalTo($image), $thumbConfig)
606
            ->will($this->returnArgument(0))
607
        ;
608
609
        $filterManager = new FilterManager(
610
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
611
            $imagineMock,
612
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
613
        );
614
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 601 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
615
616
        $filteredBinary = $filterManager->apply($binary, array(
617
            'filters' => array(
618
                'thumbnail' => $thumbConfig,
619
            ),
620
            'post_processors' => array(),
621
        ));
622
623
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
624
        $this->assertEquals($expectedFilteredContent, $filteredBinary->getContent());
625
    }
626
627 View Code Duplication
    public function testReturnFilteredBinaryWithFormatOfOriginalBinaryOnApply()
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...
628
    {
629
        $originalContent = 'aOriginalContent';
630
        $expectedFormat = 'png';
631
632
        $binary = new Binary($originalContent, 'image/png', $expectedFormat);
633
634
        $thumbConfig = array(
635
            'size' => array(180, 180),
636
            'mode' => 'outbound',
637
        );
638
639
        $image = $this->getMockImage();
640
        $image
641
            ->expects($this->once())
642
            ->method('get')
643
            ->will($this->returnValue('aFilteredContent'))
644
        ;
645
646
        $imagineMock = $this->createImagineMock();
647
        $imagineMock
648
            ->expects($this->once())
649
            ->method('load')
650
            ->will($this->returnValue($image))
651
        ;
652
653
        $loader = $this->getMockLoader();
654
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
655
            ->expects($this->once())
656
            ->method('load')
657
            ->with($this->identicalTo($image), $thumbConfig)
658
            ->will($this->returnArgument(0))
659
        ;
660
661
        $filterManager = new FilterManager(
662
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
663
            $imagineMock,
664
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
665
        );
666
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 653 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
667
668
        $filteredBinary = $filterManager->apply($binary, array(
669
            'filters' => array(
670
                'thumbnail' => $thumbConfig,
671
            ),
672
            'post_processors' => array(),
673
        ));
674
675
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
676
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
677
    }
678
679 View Code Duplication
    public function testReturnFilteredBinaryWithCustomFormatIfSetOnApply()
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...
680
    {
681
        $originalContent = 'aOriginalContent';
682
        $originalFormat = 'png';
683
        $expectedFormat = 'jpg';
684
685
        $binary = new Binary($originalContent, 'image/png', $originalFormat);
686
687
        $thumbConfig = array(
688
            'size' => array(180, 180),
689
            'mode' => 'outbound',
690
        );
691
692
        $image = $this->getMockImage();
693
        $image
694
            ->expects($this->once())
695
            ->method('get')
696
            ->will($this->returnValue('aFilteredContent'))
697
        ;
698
699
        $imagineMock = $this->createImagineMock();
700
        $imagineMock
701
            ->expects($this->once())
702
            ->method('load')
703
            ->will($this->returnValue($image))
704
        ;
705
706
        $loader = $this->getMockLoader();
707
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
708
            ->expects($this->once())
709
            ->method('load')
710
            ->with($this->identicalTo($image), $thumbConfig)
711
            ->will($this->returnArgument(0))
712
        ;
713
714
        $filterManager = new FilterManager(
715
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
716
            $imagineMock,
717
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
718
        );
719
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 706 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
720
721
        $filteredBinary = $filterManager->apply($binary, array(
722
            'format' => $expectedFormat,
723
            'filters' => array(
724
                'thumbnail' => $thumbConfig,
725
            ),
726
            'post_processors' => array(),
727
        ));
728
729
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
730
        $this->assertEquals($expectedFormat, $filteredBinary->getFormat());
731
    }
732
733
    public function testReturnFilteredBinaryWithMimeTypeOfOriginalBinaryOnApply()
734
    {
735
        $originalContent = 'aOriginalContent';
736
        $expectedMimeType = 'image/png';
737
738
        $binary = new Binary($originalContent, $expectedMimeType, 'png');
739
740
        $thumbConfig = array(
741
            'size' => array(180, 180),
742
            'mode' => 'outbound',
743
        );
744
745
        $image = $this->getMockImage();
746
        $image
747
            ->expects($this->once())
748
            ->method('get')
749
            ->will($this->returnValue('aFilteredContent'))
750
        ;
751
752
        $imagineMock = $this->createImagineMock();
753
        $imagineMock
754
            ->expects($this->once())
755
            ->method('load')
756
            ->will($this->returnValue($image))
757
        ;
758
759
        $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
760
        $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Binary\MimeTypeGuesserInterface.

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...
761
            ->expects($this->never())
762
            ->method('guess')
763
        ;
764
765
        $loader = $this->getMockLoader();
766
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
767
            ->expects($this->once())
768
            ->method('load')
769
            ->with($this->identicalTo($image), $thumbConfig)
770
            ->will($this->returnArgument(0))
771
        ;
772
773
        $filterManager = new FilterManager(
774
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
775
            $imagineMock,
776
            $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeGuesser defined by $this->getMockMimeTypeGuesser() on line 759 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, 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...
777
        );
778
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 765 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
779
780
        $filteredBinary = $filterManager->apply($binary, array(
781
            'filters' => array(
782
                'thumbnail' => $thumbConfig,
783
            ),
784
            'post_processors' => array(),
785
        ));
786
787
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
788
        $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType());
789
    }
790
791
    public function testReturnFilteredBinaryWithMimeTypeOfCustomFormatIfSetOnApply()
792
    {
793
        $originalContent = 'aOriginalContent';
794
        $originalMimeType = 'image/png';
795
        $expectedContent = 'aFilteredContent';
796
        $expectedMimeType = 'image/jpeg';
797
798
        $binary = new Binary($originalContent, $originalMimeType, 'png');
799
800
        $thumbConfig = array(
801
            'size' => array(180, 180),
802
            'mode' => 'outbound',
803
        );
804
805
        $image = $this->getMockImage();
806
        $image
807
            ->expects($this->once())
808
            ->method('get')
809
            ->will($this->returnValue($expectedContent))
810
        ;
811
812
        $imagineMock = $this->createImagineMock();
813
        $imagineMock
814
            ->expects($this->once())
815
            ->method('load')
816
            ->will($this->returnValue($image))
817
        ;
818
819
        $mimeTypeGuesser = $this->getMockMimeTypeGuesser();
820
        $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Binary\MimeTypeGuesserInterface.

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...
821
            ->expects($this->once())
822
            ->method('guess')
823
            ->with($expectedContent)
824
            ->will($this->returnValue($expectedMimeType))
825
        ;
826
827
        $loader = $this->getMockLoader();
828
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
829
            ->expects($this->once())
830
            ->method('load')
831
            ->with($this->identicalTo($image), $thumbConfig)
832
            ->will($this->returnArgument(0))
833
        ;
834
835
        $filterManager = new FilterManager(
836
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
837
            $imagineMock,
838
            $mimeTypeGuesser
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeGuesser defined by $this->getMockMimeTypeGuesser() on line 819 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, 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...
839
        );
840
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 827 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
841
842
        $filteredBinary = $filterManager->apply($binary, array(
843
            'format' => 'jpg',
844
            'filters' => array(
845
                'thumbnail' => $thumbConfig,
846
            ),
847
            'post_processors' => array(),
848
        ));
849
850
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
851
        $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType());
852
    }
853
854 View Code Duplication
    public function testAltersQualityOnApply()
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...
855
    {
856
        $originalContent = 'aOriginalContent';
857
        $expectedQuality = 80;
858
859
        $binary = new Binary($originalContent, 'image/png', 'png');
860
861
        $thumbConfig = array(
862
            'size' => array(180, 180),
863
            'mode' => 'outbound',
864
        );
865
866
        $image = $this->getMockImage();
867
        $image
868
            ->expects($this->once())
869
            ->method('get')
870
            ->with('png', array('quality' => $expectedQuality))
871
            ->will($this->returnValue('aFilteredContent'))
872
        ;
873
874
        $imagineMock = $this->createImagineMock();
875
        $imagineMock
876
            ->expects($this->once())
877
            ->method('load')
878
            ->will($this->returnValue($image))
879
        ;
880
881
        $loader = $this->getMockLoader();
882
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
883
            ->expects($this->once())
884
            ->method('load')
885
            ->with($this->identicalTo($image), $thumbConfig)
886
            ->will($this->returnArgument(0))
887
        ;
888
889
        $filterManager = new FilterManager(
890
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
891
            $imagineMock,
892
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
893
        );
894
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 881 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
895
896
        $filteredBinary = $filterManager->apply($binary, array(
897
            'quality' => $expectedQuality,
898
            'filters' => array(
899
                'thumbnail' => $thumbConfig,
900
            ),
901
            'post_processors' => array(),
902
        ));
903
904
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
905
    }
906
907 View Code Duplication
    public function testAlters100QualityIfNotSetOnApply()
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...
908
    {
909
        $originalContent = 'aOriginalContent';
910
        $expectedQuality = 100;
911
912
        $binary = new Binary($originalContent, 'image/png', 'png');
913
914
        $thumbConfig = array(
915
            'size' => array(180, 180),
916
            'mode' => 'outbound',
917
        );
918
919
        $image = $this->getMockImage();
920
        $image
921
            ->expects($this->once())
922
            ->method('get')
923
            ->with('png', array('quality' => $expectedQuality))
924
            ->will($this->returnValue('aFilteredContent'))
925
        ;
926
927
        $imagineMock = $this->createImagineMock();
928
        $imagineMock
929
            ->expects($this->once())
930
            ->method('load')
931
            ->will($this->returnValue($image))
932
        ;
933
934
        $loader = $this->getMockLoader();
935
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
936
            ->expects($this->once())
937
            ->method('load')
938
            ->with($this->identicalTo($image), $thumbConfig)
939
            ->will($this->returnArgument(0))
940
        ;
941
942
        $filterManager = new FilterManager(
943
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
944
            $imagineMock,
945
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
946
        );
947
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 934 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
948
949
        $filteredBinary = $filterManager->apply($binary, array(
950
            'filters' => array(
951
                'thumbnail' => $thumbConfig,
952
            ),
953
            'post_processors' => array(),
954
        ));
955
956
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
957
    }
958
959
    public function testApplyPostProcessor()
960
    {
961
        $originalContent = 'aContent';
962
        $expectedPostProcessedContent = 'postProcessedContent';
963
        $binary = new Binary($originalContent, 'image/png', 'png');
964
965
        $thumbConfig = array(
966
            'size' => array(180, 180),
967
            'mode' => 'outbound',
968
        );
969
970
        $config = $this->createFilterConfigurationMock();
971
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
972
            ->expects($this->atLeastOnce())
973
            ->method('get')
974
            ->with('thumbnail')
975
            ->will($this->returnValue(array(
976
                'filters' => array(
977
                    'thumbnail' => $thumbConfig,
978
                ),
979
                'post_processors' => array(
980
                    'foo' => array(),
981
                ),
982
            )))
983
        ;
984
985
        $thumbConfig = array(
986
            'size' => array(180, 180),
987
            'mode' => 'outbound',
988
        );
989
990
        $image = $this->getMockImage();
991
        $image
992
            ->expects($this->once())
993
            ->method('get')
994
            ->will($this->returnValue($originalContent))
995
        ;
996
997
        $imagineMock = $this->createImagineMock();
998
        $imagineMock
999
            ->expects($this->once())
1000
            ->method('load')
1001
            ->with($originalContent)
1002
            ->will($this->returnValue($image))
1003
        ;
1004
1005
        $loader = $this->getMockLoader();
1006
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
1007
            ->expects($this->once())
1008
            ->method('load')
1009
            ->with($this->identicalTo($image), $thumbConfig)
1010
            ->will($this->returnArgument(0))
1011
        ;
1012
1013
        $processedBinary = new Binary($expectedPostProcessedContent, 'image/png', 'png');
1014
1015
        $postProcessor = $this->getPostProcessorMock();
1016
        $postProcessor
1017
            ->expects($this->once())
1018
            ->method('process')
1019
            ->with($binary)
1020
            ->will($this->returnValue($processedBinary));
1021
1022
        $filterManager = new FilterManager(
1023
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 970 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
1024
            $imagineMock,
1025
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1026
        );
1027
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 1005 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
1028
        $filterManager->addPostProcessor('foo', $postProcessor);
1029
1030
        $filteredBinary = $filterManager->applyFilter($binary, 'thumbnail');
1031
        $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary);
1032
        $this->assertEquals($expectedPostProcessedContent, $filteredBinary->getContent());
1033
    }
1034
1035
    public function testThrowsIfNoPostProcessorAddedForFilterOnApplyFilter()
1036
    {
1037
        $originalContent = 'aContent';
1038
        $binary = new Binary($originalContent, 'image/png', 'png');
1039
1040
        $thumbConfig = array(
1041
            'size' => array(180, 180),
1042
            'mode' => 'outbound',
1043
        );
1044
1045
        $config = $this->createFilterConfigurationMock();
1046
        $config
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...ter\FilterConfiguration.

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...
1047
            ->expects($this->atLeastOnce())
1048
            ->method('get')
1049
            ->with('thumbnail')
1050
            ->will($this->returnValue(array(
1051
                'filters' => array(
1052
                    'thumbnail' => $thumbConfig,
1053
                ),
1054
                'post_processors' => array(
1055
                    'foo' => array(),
1056
                ),
1057
            )))
1058
        ;
1059
1060
        $thumbConfig = array(
1061
            'size' => array(180, 180),
1062
            'mode' => 'outbound',
1063
        );
1064
1065
        $image = $this->getMockImage();
1066
        $image
1067
            ->expects($this->once())
1068
            ->method('get')
1069
            ->will($this->returnValue($originalContent))
1070
        ;
1071
1072
        $imagineMock = $this->createImagineMock();
1073
        $imagineMock
1074
            ->expects($this->once())
1075
            ->method('load')
1076
            ->with($originalContent)
1077
            ->will($this->returnValue($image))
1078
        ;
1079
1080
        $loader = $this->getMockLoader();
1081
        $loader
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Liip\ImagineBundle\Imagi...\Loader\LoaderInterface.

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...
1082
            ->expects($this->once())
1083
            ->method('load')
1084
            ->with($this->identicalTo($image), $thumbConfig)
1085
            ->will($this->returnArgument(0))
1086
        ;
1087
1088
        $filterManager = new FilterManager(
1089
            $config,
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->createFilterConfigurationMock() on line 1045 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, 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...
1090
            $imagineMock,
1091
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1092
        );
1093
        $filterManager->addLoader('thumbnail', $loader);
0 ignored issues
show
Bug introduced by
It seems like $loader defined by $this->getMockLoader() on line 1080 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...terManager::addLoader() does only seem to accept object<Liip\ImagineBundl...Loader\LoaderInterface>, 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...
1094
1095
        $this->setExpectedException('InvalidArgumentException', 'Could not find post processor "foo"');
1096
1097
        $filterManager->applyFilter($binary, 'thumbnail');
1098
    }
1099
1100
    public function testApplyPostProcessorsWhenNotDefined()
1101
    {
1102
        $binary = $this->getMock('Liip\ImagineBundle\Binary\BinaryInterface');
1103
        $filterManager = new FilterManager(
1104
            $this->createFilterConfigurationMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->createFilterConfigurationMock() targeting Liip\ImagineBundle\Tests...lterConfigurationMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...er\FilterConfiguration>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1105
            $this->createImagineMock(),
1106
            $this->getMockMimeTypeGuesser()
0 ignored issues
show
Bug introduced by
It seems like $this->getMockMimeTypeGuesser() targeting Liip\ImagineBundle\Tests...etMockMimeTypeGuesser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Liip\ImagineBundle\Imagi...rManager::__construct() does only seem to accept object<Liip\ImagineBundl...meTypeGuesserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1107
        );
1108
1109
        $this->assertSame($binary, $filterManager->applyPostProcessors($binary, array()));
1110
    }
1111
1112
    /**
1113
     * @return \PHPUnit_Framework_MockObject_MockObject|LoaderInterface
1114
     */
1115
    protected function getMockLoader()
1116
    {
1117
        return $this->getMock('Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface');
1118
    }
1119
1120
    /**
1121
     * @return \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Binary\MimeTypeGuesserInterface
1122
     */
1123
    protected function getMockMimeTypeGuesser()
1124
    {
1125
        return $this->getMock('Liip\ImagineBundle\Binary\MimeTypeGuesserInterface');
1126
    }
1127
1128
    protected function getPostProcessorMock()
1129
    {
1130
        return $this->getMock('Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface');
1131
    }
1132
}
1133