Completed
Push — master ( b7e254...bcf326 )
by
unknown
09:07
created

PaymentNewUnitRefundGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 21 3
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.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusMolliePlugin\Refund\Generator;
14
15
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItem;
16
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItems;
17
use Sylius\Component\Core\Model\OrderInterface;
18
19
final class PaymentNewUnitRefundGenerator implements PaymentNewUnitRefundGeneratorInterface
20
{
21
    public function generate(OrderInterface $order, PartialRefundItems $partialRefundItems): PartialRefundItems
22
    {
23
        $units = $order->getItemUnits();
24
25
        foreach ($units as $unit) {
26
            if ($partialRefundItem = $partialRefundItems->findById($unit->getId())) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $partialRefundItem is correct as $partialRefundItems->findById($unit->getId()) targeting BitBag\SyliusMolliePlugi...RefundItems::findById() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
                $partialRefundItem->setAmountTotal($unit->getTotal());
28
29
                continue;
30
            }
31
32
            $partialRefundItem = new PartialRefundItem();
33
34
            $partialRefundItem->setId($unit->getId());
35
            $partialRefundItem->setAmountRefunded(0);
36
            $partialRefundItem->setAmountTotal($unit->getTotal());
37
38
            $partialRefundItems->setPartialRefundItems($partialRefundItem);
39
        }
40
41
        return $partialRefundItems;
42
    }
43
}
44