Issues (59)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Tests/Unit/Service/SettingsManagerTest.php (48 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\Tests\Unit\Service;
13
14
use Doctrine\Common\Cache\PhpFileCache;
15
use ONGR\CookiesBundle\Cookie\Model\GenericCookie;
16
use ONGR\ElasticsearchBundle\Result\DocumentIterator;
17
use ONGR\ElasticsearchBundle\Service\Manager;
18
use ONGR\ElasticsearchBundle\Service\Repository;
19
use ONGR\ElasticsearchDSL\Search;
20
use ONGR\SettingsBundle\Document\Setting;
21
use ONGR\SettingsBundle\Service\SettingsManager;
22
23
class SettingsManagerTest extends \PHPUnit_Framework_TestCase
24
{
25
26
    /**
27
     * @var Manager|\PHPUnit_Framework_MockObject_MockObject
28
     */
29
    private $manager;
30
31
    /**
32
     * @var Repository|\PHPUnit_Framework_MockObject_MockObject
33
     */
34
    private $repository;
35
36
    /**
37
     * @var PhpFileCache|\PHPUnit_Framework_MockObject_MockObject
38
     */
39
    private $cache;
40
41
    /**
42
     * @var GenericCookie|\PHPUnit_Framework_MockObject_MockObject
43
     */
44
    private $cookie;
45
46
    public function setUp()
47
    {
48
        $this->manager = $this->getMockBuilder('ONGR\ElasticsearchBundle\Service\Manager')
49
            ->disableOriginalConstructor()
50
            ->setMethods(['persist', 'commit'])
51
            ->getMock();
52
        $this->cache = $this->getMockBuilder('Doctrine\Common\Cache\PhpFileCache')
53
            ->disableOriginalConstructor()
54
            ->setMethods(['contains', 'fetch', 'save', 'delete'])
55
            ->getMock();
56
        $this->cookie = $this->getMockBuilder('ONGR\CookiesBundle\Cookie\Model\GenericCookie')
57
            ->disableOriginalConstructor()
58
            ->setMethods(['getValue'])
59
            ->getMock();
60
        $this->repository = $this->getMockBuilder('ONGR\ElasticsearchBundle\Service\Repository')
61
            ->disableOriginalConstructor()
62
            ->setMethods(
63
                [
64
                    'findOneBy',
65
                    'remove',
66
                    'createSearch',
67
                    'findDocuments',
68
                    'getClassName',
69
                    'getManager',
70
                    'getAggregation',
71
                ]
72
            )
73
            ->getMock();
74
75
        $this->repository->expects($this->any())->method('getClassName')->willReturn(Setting::class);
76
        $this->repository->expects($this->any())->method('getManager')->willReturn($this->manager);
77
        $this->repository->expects($this->any())->method('createSearch')->willReturn(new Search());
78
    }
79
80
    /**
81
     * Test get cache getter.
82
     */
83
    public function testGetCache()
84
    {
85
        $manager = new SettingsManager(
86
            $this->repository,
87
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
88
        );
89
        $manager->setCache($this->cache);
90
91
        $this->assertInstanceOf('Doctrine\Common\Cache\PhpFileCache', $manager->getCache());
92
    }
93
94
    /**
95
     * Test get cookie getter.
96
     */
97
    public function testGetActiveProfilesCookie()
98
    {
99
        $manager = new SettingsManager(
100
            $this->repository,
101
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
102
        );
103
        $manager->setActiveProfilesCookie($this->cookie);
104
105
        $this->assertInstanceOf('ONGR\CookiesBundle\Cookie\Model\GenericCookie', $manager->getActiveProfilesCookie());
106
    }
107
108
    /**
109
     * Test get cookie getter.
110
     */
111
    public function testGetActiveProfilesSettingName()
112
    {
113
        $manager = new SettingsManager(
114
            $this->repository,
115
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
116
        );
117
        $manager->setActiveProfilesSettingName('ongr');
118
119
        $this->assertEquals('ongr', $manager->getActiveProfilesSettingName());
120
    }
121
122
    /**
123
     * Test setting create function.
124
     */
125
    public function testCreate()
126
    {
127
        $data = [
128
            'name' => 'acme',
129
            'type' => 'string',
130
            'value' => 'foo',
131
        ];
132
133
        $this->manager->expects($this->once())->method('persist')->with($this->callback(function ($obj) {
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Manager.

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...
134
            return $obj instanceof Setting;
135
        }))->willReturn(null);
136
        $this->manager->expects($this->once())->method('persist')->willReturn(null);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Manager.

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...
137
138
        $manager = new SettingsManager(
139
            $this->repository,
140
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
141
        );
142
        $document = $manager->create($data);
143
144
        foreach ($data as $key => $value) {
145
            $this->assertEquals($value, $document->{'get' . ucfirst($key)}());
146
        }
147
    }
148
149
    /**
150
     * @expectedException \LogicException
151
     * @expectedExceptionMessage Missing one of the mandatory field!
152
     */
153
    public function testCreateMandatoryParameters()
154
    {
155
        $data = ['bar' => 'foo'];
156
157
        $manager = new SettingsManager(
158
            $this->repository,
159
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
160
        );
161
        $manager->create($data);
162
    }
163
164
    /**
165
     * @expectedException \LogicException
166
     * @expectedExceptionMessage Setting acme already exists.
167
     */
168
    public function testCreateWhenSettingExists()
169
    {
170
        $data = [
171
            'name' => 'acme',
172
            'type' => 'string',
173
            'value' => 'foo',
174
        ];
175
176
        $this->repository->expects($this->once())->method('findOneBy')->willReturn(new Setting());
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
177
178
        $manager = new SettingsManager(
179
            $this->repository,
180
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
181
        );
182
        $manager->create($data);
183
    }
184
185
    /**
186
     * Tests setting create without value set. Should be set to 0 by default.
187
     */
188
    public function testWithoutDataValueSet()
189
    {
190
        $data = [
191
            'name' => 'acme',
192
            'type' => 'string',
193
        ];
194
195
        $manager = new SettingsManager(
196
            $this->repository,
197
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
198
        );
199
        $document = $manager->create($data);
200
201
        $this->assertEquals(0, $document->getValue());
202
    }
203
204
    /**
205
     * Tests setting update.
206
     */
207
    public function testUpdate()
208
    {
209
        $setting = new Setting();
210
        $setting->setName('acme');
211
        $setting->setValue('foo');
212
213
        $this->repository->expects($this->once())->method('findOneBy')->willReturn($setting);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
214
        $manager = new SettingsManager(
215
            $this->repository,
216
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
217
        );
218
        $manager->setCache($this->cache);
219
220
        $document = $manager->update('acme', ['value' => 'bar']);
221
        $this->assertEquals('acme', $document->getName());
222
        $this->assertEquals('bar', $document->getValue());
223
    }
224
225
    /**
226
     * @expectedException \LogicException
227
     * @expectedExceptionMessage Setting acme not exist.
228
     */
229 View Code Duplication
    public function testUpdateWhenSettingNotExists()
0 ignored issues
show
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...
230
    {
231
        $this->repository->expects($this->once())->method('findOneBy')->willReturn(null);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
232
233
        $manager = new SettingsManager(
234
            $this->repository,
235
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
236
        );
237
        $manager->setCache($this->cache);
238
        $manager->update('acme', ['value' => 'foo']);
239
    }
240
241
    /**
242
     * Tests setting delete.
243
     */
244 View Code Duplication
    public function testDelete()
0 ignored issues
show
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...
245
    {
246
        $setting = new Setting();
247
        $setting->setId('acme');
248
        $setting->setName('acme');
249
250
        $this->repository->expects($this->any())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
251
            ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn($setting);
252
        $manager = new SettingsManager(
253
            $this->repository,
254
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
255
        );
256
        $manager->setCache($this->cache);
257
258
        $manager->delete('acme');
259
    }
260
261 View Code Duplication
    public function testHas()
0 ignored issues
show
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...
262
    {
263
        $setting = new Setting();
264
        $setting->setName('acme');
265
        $setting->setValue('foo');
266
267
        $this->repository->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
268
            ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn($setting);
269
        $manager = new SettingsManager(
270
            $this->repository,
271
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
272
        );
273
274
        $result = $manager->has('acme');
275
276
        $this->assertTrue($result);
277
    }
278
279
    /**
280
     * Test has method when there is no setting.
281
     */
282 View Code Duplication
    public function testHasWhenThereIsNoSetting()
0 ignored issues
show
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...
283
    {
284
        $this->repository->expects($this->once())
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
285
            ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn(null);
286
        $manager = new SettingsManager(
287
            $this->repository,
288
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
289
        );
290
291
        $result = $manager->has('acme');
292
293
        $this->assertFalse($result);
294
    }
295
296
    /**
297
     * Tests setting update.
298
     */
299 View Code Duplication
    public function testGetValue()
0 ignored issues
show
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...
300
    {
301
        $setting = new Setting();
302
        $setting->setName('acme');
303
        $setting->setValue('foo');
304
305
        $this->repository->expects($this->once())->method('findOneBy')->willReturn($setting);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
306
        $manager = new SettingsManager(
307
            $this->repository,
308
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
309
        );
310
311
        $result = $manager->getValue('acme');
312
        $this->assertEquals('foo', $result);
313
    }
314
315
    /**
316
     * Tests setting update.
317
     */
318 View Code Duplication
    public function testGetValueWhenThereIsNoSetting()
0 ignored issues
show
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...
319
    {
320
        $this->repository->expects($this->once())->method('findOneBy')->willReturn(null);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
321
        $manager = new SettingsManager(
322
            $this->repository,
323
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
324
        );
325
326
        $result = $manager->getValue('acme', 'bar');
0 ignored issues
show
'bar' is of type string, but the function expects a boolean|null.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
327
        $this->assertEquals('bar', $result);
328
    }
329
330
    /**
331
     * Returns document iterator with pre-loaded aggregations.
332
     *
333
     * @return DocumentIterator
334
     */
335
    private function getDocumentIterator()
336
    {
337
        $rawData = [
338
            'aggregations' => [
339
                'filter' => [
340
                    'profiles' => [
341
                        'buckets' => [
342
                            [
343
                                'key' => 'default',
344
                                'doc_count' => 2,
345
                                'documents' => [
346
                                    'hits' => [
347
                                        'total' => 2,
348
                                        'max_score' => 1,
349
                                        'hits' => [
350
                                            [
351
                                                '_index' => 'settings',
352
                                                '_type' => 'setting',
353
                                                '_id' => 'kk',
354
                                                '_score' => 1,
355
                                                '_source' => [
356
                                                    'name' => 'foo',
357
                                                    'profile' => [
358
                                                        'bar'
359
                                                    ],
360
                                                    'type' => 'bool',
361
                                                    'value' => 1
362
                                                ]
363
                                            ],
364
                                            [
365
                                                '_index' => 'settings',
366
                                                '_type' => 'setting',
367
                                                '_id' => 'xx',
368
                                                '_score' => 1,
369
                                                '_source' => [
370
                                                    'name' => 'kk',
371
                                                    'profile' => [
372
                                                        'kk'
373
                                                    ],
374
                                                    'type' => 'bool',
375
                                                    'value' => 1
376
                                                ]
377
                                            ]
378
                                        ]
379
                                    ]
380
                                ],
381
                                'key' => 'foo',
382
                                'doc_count' => 1,
383
                                'documents' => [
384
                                    'hits' => [
385
                                        'total' => 1,
386
                                        'max_score' => 1,
387
                                        'hits' => [
388
                                            [
389
                                                '_index' => 'settings',
390
                                                '_type' => 'setting',
391
                                                '_id' => 'kk',
392
                                                '_score' => 1,
393
                                                '_source' => [
394
                                                    'name' => 'foo',
395
                                                    'profile' => [
396
                                                        'bar'
397
                                                    ],
398
                                                    'type' => 'bool',
399
                                                    'value' => 1
400
                                                ]
401
                                            ]
402
                                        ]
403
                                    ]
404
                                ],
405
                                'key' => 'kk',
406
                                'doc_count' => 1,
407
                                'documents' => [
408
                                    'hits' => [
409
                                        'total' => 1,
410
                                        'max_score' => 1,
411
                                        'hits' => [
412
                                            [
413
                                                '_index' => 'settings',
414
                                                '_type' => 'setting',
415
                                                '_id' => 'kk',
416
                                                '_score' => 1,
417
                                                '_source' => [
418
                                                    'name' => 'foo',
419
                                                    'profile' => [
420
                                                        'bar'
421
                                                    ],
422
                                                    'type' => 'bool',
423
                                                    'value' => 1
424
                                                ]
425
                                            ]
426
                                        ]
427
                                    ]
428
                                ]
429
                            ]
430
                        ]
431
                    ]
432
                ]
433
            ]
434
        ];
435
436
        return new DocumentIterator($rawData, $this->manager);
437
    }
438
439
    /**
440
     * Tests setting update.
441
     */
442
    public function testGetCachedValue()
443
    {
444
445
        $activeProfilesSetting = 'active_profiles';
446
447
        $this->repository->expects($this->any())->method('findOneBy')->willReturnCallback(
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
448
            function ($arg) use ($activeProfilesSetting) {
449
                $settingName = $arg['name.name'];
450
                $setting = new Setting();
451
                switch ($settingName) {
452
                    case 'active_profiles':
453
                        $setting->setName($activeProfilesSetting);
454
                        $setting->setValue(['bar', 'foo']);
0 ignored issues
show
array('bar', 'foo') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
455
                        return $setting;
456
                        break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
457
                    case 'acme':
458
                        $setting->setName('acme');
459
                        $setting->setValue('foo');
460
                        $setting->setProfile(['foo', 'default']);
461
                        break;
462
                }
463
                return $setting;
464
            }
465
        );
466
467
        $this->repository->expects($this->any())->method('findDocuments')->willReturn($this->getDocumentIterator());
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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

Let’s take a look at an example:

class A
{
    public function foo() { }
}

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

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

Available Fixes

  1. Add an additional type-check:

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

    function someFunction(B $x) { /** ... */ }
    
Loading history...
468
        $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie.

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...
469
470
        $manager = new SettingsManager(
471
            $this->repository,
472
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
473
        );
474
        $manager->setCache($this->cache);
475
        $manager->setActiveProfilesSettingName($activeProfilesSetting);
476
        $manager->setActiveProfilesCookie($this->cookie);
477
        $manager->setActiveProfilesList(['default']);
478
479
        $result = $manager->getCachedValue('acme');
480
        $this->assertEquals('foo', $result);
481
    }
482
483
    /**
484
     * Tests setting update.
485
     */
486
    public function testGetCachedValueFromCache()
487
    {
488
489
        $activeProfilesSetting = 'active_profiles';
490
491
        $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator());
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
492
        $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie.

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...
493
        $this->cache->expects($this->any())->method('contains')->willReturn(true);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\PhpFileCache.

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...
494
        $this->cache->expects($this->any())->method('fetch')->willReturnCallback(
495
            function ($arg) use ($activeProfilesSetting) {
496
                if ($arg == $activeProfilesSetting) {
497
                    return ['foo'];
498
                }
499
                return ['value' => 'foo', 'profiles' => ['foo']];
500
            }
501
        );
502
503
        $manager = new SettingsManager(
504
            $this->repository,
505
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
506
        );
507
        $manager->setCache($this->cache);
508
        $manager->setActiveProfilesSettingName($activeProfilesSetting);
509
        $manager->setActiveProfilesCookie($this->cookie);
510
511
        $result = $manager->getCachedValue('acme');
512
        $this->assertEquals('foo', $result);
513
    }
514
515
    /**
516
     * Tests setting update.
517
     */
518
    public function testGetCachedValueWithoutActiveProfiles()
519
    {
520
        $activeProfilesSetting = 'active_profiles';
521
        $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator());
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
522
        $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie.

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...
523
        $this->cache->expects($this->any())->method('contains')->willReturn(true);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\PhpFileCache.

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...
524
        $this->cache->expects($this->any())->method('fetch')->willReturn(['value' => 'foo', 'profiles' => ['foo']]);
525
526
        $manager = new SettingsManager(
527
            $this->repository,
528
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
529
        );
530
        $manager->setCache($this->cache);
531
        $manager->setActiveProfilesSettingName($activeProfilesSetting);
532
        $manager->setActiveProfilesCookie($this->cookie);
533
534
        $result = $manager->getCachedValue('acme', false);
535
        $this->assertEquals('foo', $result);
536
    }
537
538
    /**
539
     * Tests if there is no setting.
540
     */
541
    public function testGetCachedValueWhenItsNotExist()
542
    {
543
        $activeProfilesSetting = 'active_profiles';
544
        $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator());
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
545
        $manager = new SettingsManager(
546
            $this->repository,
547
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
548
        );
549
        $manager->setCache($this->cache);
550
        $manager->setActiveProfilesSettingName($activeProfilesSetting);
551
552
        $value = $manager->getCachedValue('acme');
553
        $this->assertNull($value);
554
    }
555
556
    public function testGetAllActiveProfilesNameList()
557
    {
558
        $document = new Setting();
559
        $document->setName('active_profiles');
560
        $document->setValue(['kk']);
0 ignored issues
show
array('kk') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
561
        $this->repository->expects($this->any())->method('findOneBy')->willReturn($document);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
562
        $this->repository->expects($this->any())->method('findDocuments')->willReturn($this->getDocumentIterator());
563
        $manager = new SettingsManager(
564
            $this->repository,
565
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
566
        );
567
        $manager->setCache($this->cache);
568
569
        $value = $manager->getActiveProfiles();
570
        $this->assertEquals(['kk'], $value);
571
    }
572
573
    public function testGetActiveExperimentsFromRepository()
574
    {
575
        $activeExperimentsSettingName = 'foo';
576
        $experimentName = 'bar';
577
        $cache = $this->cache;
578
        $cache->expects($this->any())->method('contains')->willReturn(false);
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\PhpFileCache.

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...
579
        $activeExperiments = new Setting;
580
        $activeExperiments->setName($activeExperimentsSettingName);
581
        $activeExperiments->setValue([$experimentName]);
0 ignored issues
show
array($experimentName) is of type array<integer,string,{"0":"string"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
582
        $repository = $this->repository;
583
        $repository->expects($this->any())->method('findOneBy')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
584
            ->with(['name.name' => $activeExperimentsSettingName])->willReturn($activeExperiments);
585
        $manager = new SettingsManager(
586
            $repository,
0 ignored issues
show
It seems like $repository defined by $this->repository on line 582 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository>, 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...
587
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
588
        );
589
        $manager->setActiveExperimentsSettingName($activeExperimentsSettingName);
590
        $manager->setCache($cache);
0 ignored issues
show
It seems like $cache defined by $this->cache on line 577 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider>, 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...
591
592
        $activeExperiments = $manager->getActiveExperiments();
593
594
        $this->assertEquals([$experimentName], $activeExperiments);
595
    }
596
597 View Code Duplication
    public function testGetActiveExperimentsFromCache()
0 ignored issues
show
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...
598
    {
599
        $activeExperimentsSettingName = 'foo';
600
        $experimentName = 'bar';
601
        $cache = $this->cache;
602
        $cache->expects($this->any())->method('contains')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\PhpFileCache.

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
            ->with($activeExperimentsSettingName)->willReturn(true);
604
        $cache->expects($this->any())->method('fetch')
605
            ->with($activeExperimentsSettingName)->willReturn(['value' => [$experimentName]]);
606
        $manager = new SettingsManager(
607
            $this->repository,
608
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
609
        );
610
        $manager->setActiveExperimentsSettingName($activeExperimentsSettingName);
611
        $manager->setCache($cache);
0 ignored issues
show
It seems like $cache defined by $this->cache on line 601 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider>, maybe add an additional type check?

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

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

    return array();
}

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

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

Loading history...
612
613
        $activeExperiments = $manager->getActiveExperiments();
614
615
        $this->assertEquals([$experimentName], $activeExperiments);
616
    }
617
618 View Code Duplication
    public function testGetActiveExperimentsCreateNew()
0 ignored issues
show
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...
619
    {
620
        $activeExperimentsSettingName = 'foo';
621
        $cache = $this->cache;
622
        $cache->expects($this->any())->method('contains')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\PhpFileCache.

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...
623
            ->with($activeExperimentsSettingName)->willReturn(false);
624
        $repository = $this->repository;
625
        $repository->expects($this->any())->method('findOneBy')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
626
            ->with(['name.name' => $activeExperimentsSettingName])->willReturn(null);
627
        $manager = new SettingsManager(
628
            $repository,
0 ignored issues
show
It seems like $repository defined by $this->repository on line 624 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository>, 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...
629
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
630
        );
631
        $manager->setActiveExperimentsSettingName($activeExperimentsSettingName);
632
        $manager->setCache($cache);
0 ignored issues
show
It seems like $cache defined by $this->cache on line 621 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider>, 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...
633
634
        $activeExperiments = $manager->getActiveExperiments();
635
636
        $this->assertEquals([], $activeExperiments);
637
    }
638
639
    public function testToggleExperiment()
640
    {
641
        $activeExperimentsSettingName = 'active_profiles';
642
        $activeExperimentsSetting = new Setting();
643
        $activeExperimentsSetting->setName($activeExperimentsSettingName);
644
        $repository = $this->repository;
645
        $repository->expects($this->any())->method('findOneBy')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
646
            ->with(['name.name' => $activeExperimentsSettingName])->willReturn($activeExperimentsSetting);
647
        $manager = new SettingsManager(
648
            $repository,
0 ignored issues
show
It seems like $repository defined by $this->repository on line 644 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository>, 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...
649
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
650
        );
651
        $manager->setCache($this->cache);
652
        $manager->setActiveExperimentsSettingName($activeExperimentsSettingName);
653
        $manager->toggleExperiment('foo');
654
        $this->assertEquals(['foo'], $activeExperimentsSetting->getValue());
655
    }
656
657
    /**
658
     * @expectedException \LogicException
659
     * @expectedExceptionMessage The setting `active_profiles` is not set
660
     */
661
    public function testGetCachedExperimentException()
662
    {
663
        $activeExperimentsSettingName = 'active_profiles';
664
        $repository = $this->repository;
665
        $repository->expects($this->any())->method('findOneBy')
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in ONGR\ElasticsearchBundle\Service\Repository.

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...
666
            ->with(['name.name' => $activeExperimentsSettingName])->willReturn(null);
667
        $manager = new SettingsManager(
668
            $repository,
0 ignored issues
show
It seems like $repository defined by $this->repository on line 664 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository>, 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...
669
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
670
        );
671
        $manager->setActiveExperimentsSettingName($activeExperimentsSettingName);
672
        $manager->toggleExperiment('foo');
673
    }
674
}
675