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

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