DecimalTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromFloat() 0 7 1
A testJsonSerialize() 0 10 1
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