Completed
Push — refactor ( 58c596...fef2f5 )
by Bogdan
02:50
created

ObjectMapTest::testPutAndGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
4
namespace Pinepain\ObjectMaps\Tests;
5
6
use Pinepain\ObjectMaps\ObjectMap;
7
use PHPUnit\Framework\TestCase;
8
use stdClass;
9
10
11
class ObjectMapTest extends TestCase
12
{
13
    public function testPutNonAnObjectFails()
14
    {
15
        $map = new ObjectMap();
16
17
        $map->put('foo', 'bar');
0 ignored issues
show
Documentation introduced by
'foo' is of type string, but the function expects a object.

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...
Documentation introduced by
'bar' is of type string, but the function expects a object.

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...
18
    }
19
20 View Code Duplication
    public function testPutAndGet()
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...
21
    {
22
        $map = new ObjectMap();
23
24
        $key   = new stdClass();
25
        $value = new stdClass();
26
27
        $map->put($key, $value);
28
        $this->assertSame($value, $map->get($key));
29
    }
30
}
31