TaxRule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Document;
14
15
use BitBag\SyliusVueStorefrontPlugin\Document\TaxRule\Rates;
16
17
class TaxRule implements Indexable
18
{
19
    private const ENTITY_ID = 'id';
20
21
    private const CODE = 'code';
22
23
    private const PRIORITY = 'priority';
24
25
    private const POSITION = 'position';
26
27
    private const CUSTOMER_TAX_CLASS_IDS = 'customer_tax_class_ids';
28
29
    private const PRODUCT_TAX_CLASS_IDS = 'product_tax_class_ids';
30
31
    private const TAX_RATE_IDS = 'tax_rate_ids';
32
33
    private const CALCULATE_SUBTOTAL = 'calculate_subtotal';
34
35
    private const TAX_RATES = 'rates';
36
37
    /** @var int */
38
    private $documentId;
39
40
    /** @var int */
41
    private $entityId;
42
43
    /** @var string */
44
    private $code;
45
46
    /** @var int */
47
    private $priority;
48
49
    /** @var int */
50
    private $position;
51
52
    /** @var int[] */
53
    private $customerTaxClassIds;
54
55
    /** @var int[] */
56
    private $productTaxClassIds;
57
58
    /** @var int[] */
59
    private $taxRateIds;
60
61
    /** @var bool */
62
    private $calculateSubtotal;
63
64
    /** @var Rates */
65
    private $taxRates;
66
67
    public function __construct(
68
        int $documentId,
69
        int $entityId,
70
        string $code,
71
        int $priority,
72
        int $position,
73
        array $customerTaxClassIds,
74
        array $productTaxClassIds,
75
        array $taxRateIds,
76
        bool $calculateSubtotal,
77
        Rates $taxRates
78
    ) {
79
        $this->documentId = $documentId;
80
        $this->entityId = $entityId;
81
        $this->code = $code;
82
        $this->priority = $priority;
83
        $this->position = $position;
84
        $this->customerTaxClassIds = $customerTaxClassIds;
85
        $this->productTaxClassIds = $productTaxClassIds;
86
        $this->taxRateIds = $taxRateIds;
87
        $this->calculateSubtotal = $calculateSubtotal;
88
        $this->taxRates = $taxRates;
89
    }
90
91
    public function getDocumentId(): int
92
    {
93
        return $this->documentId;
94
    }
95
96
    public function toElasticArray(): array
97
    {
98
        return [
99
            self::ENTITY_ID => $this->entityId,
100
            self::CODE => $this->code,
101
            self::PRIORITY => $this->priority,
102
            self::POSITION => $this->position,
103
            self::CUSTOMER_TAX_CLASS_IDS => $this->customerTaxClassIds,
104
            self::PRODUCT_TAX_CLASS_IDS => $this->productTaxClassIds,
105
            self::TAX_RATE_IDS => $this->taxRateIds,
106
            self::CALCULATE_SUBTOTAL => $this->calculateSubtotal,
107
            self::TAX_RATES => $this->taxRates,
108
        ];
109
    }
110
}
111