DecimalTest::testJsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Postpay\Tests\Serializers;
4
5
use PHPUnit\Framework\TestCase;
6
use Postpay\Serializers\Decimal;
7
8
class DecimalTest extends TestCase
9
{
10
    public function testFromFloat()
11
    {
12
        $value = mt_rand();
13
        $decimal = Decimal::fromFloat($value);
0 ignored issues
show
Documentation introduced by
$value is of type integer, but the function expects a object<Postpay\Serializers\DateTime>.

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...
14
15
        self::assertSame($decimal->toFloat(), $value);
16
    }
17
18
    public function testJsonSerialize()
19
    {
20
        $value = mt_rand();
21
        $decimal = Decimal::fromFloat($value);
0 ignored issues
show
Documentation introduced by
$value is of type integer, but the function expects a object<Postpay\Serializers\DateTime>.

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...
22
23
        self::assertEquals(
24
            $decimal->jsonSerialize(),
25
            json_encode($decimal, JSON_NUMERIC_CHECK)
26
        );
27
    }
28
}
29