DateTest::testFromDateTime()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Postpay\Tests\Serializers;
4
5
use DateTime;
6
use PHPUnit\Framework\TestCase;
7
use Postpay\Serializers\Date;
8
9
class DateTest extends TestCase
10
{
11
    public function testFromDateTime()
12
    {
13
        $datetime = new DateTime();
14
        $date = Date::fromDateTime($datetime);
0 ignored issues
show
Documentation introduced by
$datetime is of type object<DateTime>, 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...
15
16
        self::assertGreaterThanOrEqual($date->toDateTime(), $datetime);
17
    }
18
19
    public function testFromDate()
20
    {
21
        $datetime = new DateTime();
22
        $date = Date::fromDate($datetime);
0 ignored issues
show
Documentation introduced by
$datetime is of type object<DateTime>, 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...
23
24
        self::assertGreaterThan($date->toDateTime(), $datetime);
25
    }
26
27
    public function testJsonSerialize()
28
    {
29
        $datetime = new DateTime();
30
        $date = Date::fromDateTime($datetime);
0 ignored issues
show
Documentation introduced by
$datetime is of type object<DateTime>, 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...
31
32
        self::assertSame(
33
            $date->jsonSerialize(),
34
            trim(json_encode($date), '"')
35
        );
36
    }
37
}
38