Passed
Push — master ( cd6b77...0457a6 )
by Dmitry
32:58 queued 22:11
created

InstallmentWasFinished::getTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge\modifiers\event;
12
13
use hiqdev\php\billing\charge\ChargeInterface;
14
use League\Event\AbstractEvent;
15
16
class InstallmentWasFinished extends AbstractEvent implements \JsonSerializable
17
{
18
    /**
19
     * @var ChargeInterface
20
     */
21
    private $charge;
22
    /**
23
     * @var \DateTimeImmutable
24
     */
25
    private $time;
26
27
    private function __construct(ChargeInterface $charge, \DateTimeImmutable $time)
28
    {
29
        $this->charge = $charge;
30
        $this->time = $time;
31
    }
32
33
    public static function onCharge(ChargeInterface $charge, \DateTimeImmutable $time): self
34
    {
35
        return new self($charge, $time);
36
    }
37
38
    public function getCharge(): ChargeInterface
39
    {
40
        return $this->charge;
41
    }
42
43
    public function getTime(): \DateTimeImmutable
44
    {
45
        return $this->time;
46
    }
47
48
    /**
49
     * Specify data which should be serialized to JSON
50
     *
51
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
52
     * @return mixed data which can be serialized by <b>json_encode</b>,
53
     * which is a value of any type other than a resource
54
     * @since 5.4.0
55
     */
56
    public function jsonSerialize(): array
57
    {
58
        return [
59
            'price_id' => $this->charge->getPrice()->getId(),
60
            'part_id' => $this->charge->getPrice()->getTarget()->getId(),
61
        ];
62
    }
63
}
64