PaymentRefundedGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Refund\Generator;
13
14
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItem;
15
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItems;
16
use Sylius\Component\Core\Model\OrderInterface;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
use Sylius\RefundPlugin\Entity\RefundInterface;
19
use Sylius\RefundPlugin\Model\RefundType;
20
21
final class PaymentRefundedGenerator implements PaymentRefundedGeneratorInterface
22
{
23
    /** @var RepositoryInterface */
24
    private $refundUnitsRepository;
25
26
    public function __construct(RepositoryInterface $refundUnitsRepository)
27
    {
28
        $this->refundUnitsRepository = $refundUnitsRepository;
29
    }
30
31
    public function generate(OrderInterface $order): PartialRefundItems
32
    {
33
        $refundedUnits = $this->refundUnitsRepository->findBy([
34
            'orderNumber' => $order->getNumber(),
35
            'type' => RefundType::orderItemUnit(),
36
        ]);
37
38
        $partialRefundItems = new PartialRefundItems();
39
40
        /** @var RefundInterface $refundedUnit */
41
        foreach ($refundedUnits as $refundedUnit) {
42
            $partialRefundItem = new PartialRefundItem();
43
44
            if ($partialRefund = $partialRefundItems->findById($refundedUnit->getRefundedUnitId())) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $partialRefund is correct as $partialRefundItems->fin...t->getRefundedUnitId()) 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...
45
                $partialRefund->setAmountRefunded($refundedUnit->getAmount());
46
47
                continue;
48
            }
49
50
            $partialRefundItem->setId($refundedUnit->getRefundedUnitId());
51
            $partialRefundItem->setAmountRefunded($refundedUnit->getAmount());
52
53
            $partialRefundItems->setPartialRefundItems($partialRefundItem);
54
        }
55
56
        return $partialRefundItems;
57
    }
58
}
59