TaxRatesTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 23 4
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\Sylius\Transformer\SyliusTaxCategory;
14
15
use BitBag\SyliusVueStorefrontPlugin\Document\TaxRule\Rates;
16
use BitBag\SyliusVueStorefrontPlugin\Document\TaxRule\TaxRate\Rate;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Core\Model\TaxRateInterface;
19
20
final class TaxRatesTransformer implements TaxRatesTransformerInterface
21
{
22
    /** @param Collection|TaxRateInterface[] $taxRates */
23
    public function transform(Collection $taxRates): Rates
24
    {
25
        $rates = [];
26
        $ratesIds = [];
27
28
        foreach ($taxRates as $taxRate) {
29
            $rates[] = new Rate(
30
                $taxRate->getId(),
31
                $taxRate->getCode(),
32
                (int) $taxRate->getAmountAsPercentage(),
33
                ('country' === $taxRate->getZone()->getType()) ? $taxRate->getZone()->getName() : null,
34
                ('province' === $taxRate->getZone()->getType()) ? $taxRate->getZone()->getId() : 0,
35
                0, //postcode
36
                false,
37
                null,
38
                null
39
            );
40
41
            $ratesIds[] = $taxRate->getId();
42
        }
43
44
        return new Rates($rates, $ratesIds);
45
    }
46
}
47