InvoiceServiceItem   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 8 1
A __construct() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoman4eg\Nalog\DTO;
5
6
/**
7
 * @author Artem Dubinin <[email protected]>
8
 */
9
final class InvoiceServiceItem implements \JsonSerializable
10
{
11
    private string $name;
12
13
    /** @var float|int|string */
14
    private $amount;
15
16
    /** @var float|int */
17
    private $quantity;
18
19
    private ?int $serviceNumber;
20
21
    /**
22
     * @param float|int|string $amount
23
     * @param float|int        $quantity
24
     * @param mixed            $serviceNumber
25
     */
26
    public function __construct(string $name, $amount, $quantity, $serviceNumber = 0)
27
    {
28
        $this->name = $name;
29
        $this->amount = $amount;
30
        $this->quantity = $quantity;
31
        $this->serviceNumber = $serviceNumber;
32
    }
33
34
    public function jsonSerialize(): array
35
    {
36
        return array_filter([
37
            'name' => $this->name,
38
            'amount' => $this->amount,
39
            'quantity' => $this->quantity,
40
            'serviceNumber' => $this->serviceNumber,
41
        ], static fn ($item) => $item !== null);
42
    }
43
}
44