FromSyliusToMollieLinesResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLineIdFromMollie() 0 9 3
A resolve() 0 17 2
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
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Resolver\PartialShip;
13
14
use BitBag\SyliusMolliePlugin\DTO\PartialShipItem;
15
use BitBag\SyliusMolliePlugin\DTO\PartialShipItems;
16
use Doctrine\Common\Collections\Collection;
17
use Mollie\Api\Resources\Order;
18
use Sylius\Component\Core\Model\OrderItemUnitInterface;
19
20
final class FromSyliusToMollieLinesResolver implements FromSyliusToMollieLinesResolverInterface
21
{
22
    public function resolve(Collection $units, Order $mollieOrder): PartialShipItems
23
    {
24
        $shipItems = new PartialShipItems();
25
26
        /** @var OrderItemUnitInterface $unit */
27
        foreach ($units as $unit) {
28
            $lineId = $this->getLineIdFromMollie($mollieOrder, $unit->getOrderItem()->getId());
29
30
            $shipItem = new PartialShipItem();
31
            $shipItem->setId($unit->getOrderItem()->getId());
32
            $shipItem->setLineId($lineId);
0 ignored issues
show
Bug introduced by
It seems like $lineId can also be of type null; however, parameter $lineId of BitBag\SyliusMolliePlugi...alShipItem::setLineId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
            $shipItem->setLineId(/** @scrutinizer ignore-type */ $lineId);
Loading history...
33
            $shipItem->setQuantity(1);
34
35
            $shipItems->setPartialShipItem($shipItem);
36
        }
37
38
        return $shipItems;
39
    }
40
41
    private function getLineIdFromMollie(Order $mollieOrder, int $itemId): ?string
42
    {
43
        foreach ($mollieOrder->lines as $line) {
44
            if ($itemId === $line->metadata->item_id) {
45
                return (string) $line->id;
46
            }
47
        }
48
49
        return null;
50
    }
51
}
52