InstallmentWasFinished   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 5 1
A onCharge() 0 3 1
A getTime() 0 3 1
A __construct() 0 4 1
A getCharge() 0 3 1
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