MealVoucherResolver   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMealVoucherCategory() 0 10 3
A resolve() 0 7 2
A getMealVoucherFromItem() 0 5 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;
13
14
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
15
use BitBag\SyliusMolliePlugin\Payments\Methods\MealVoucher;
16
use Sylius\Component\Core\Model\OrderItemInterface;
17
18
final class MealVoucherResolver implements MealVoucherResolverInterface
19
{
20
    public function resolve(MollieGatewayConfigInterface $method, OrderItemInterface $item): ?string
21
    {
22
        if ($method->getMethodId() === MealVoucher::MEAL_VOUCHERS) {
23
            return $this->getMealVoucherCategory($method, $item);
24
        }
25
26
        return null;
27
    }
28
29
    private function getMealVoucherCategory(MollieGatewayConfigInterface $method, OrderItemInterface $item): ?string
30
    {
31
        if (null !== $this->getMealVoucherFromItem($item)) {
32
            return $this->getMealVoucherFromItem($item);
33
        }
34
        if (null !== $method->getDefaultCategory()) {
35
            return $method->getDefaultCategory()->getName();
36
        }
37
38
        throw new \LogicException(\sprintf('Voucher need default category, product category found in product name %s', $item->getProduct()->getName()));
39
    }
40
41
    private function getMealVoucherFromItem(OrderItemInterface $item): ?string
42
    {
43
        $product = $item->getProduct();
44
45
        return null === $product->getProductType() ? null : $product->getProductType()->getName();
0 ignored issues
show
Bug introduced by
The method getProductType() does not exist on Sylius\Component\Core\Model\ProductInterface. Did you maybe mean getProductTaxons()? ( Ignorable by Annotation )

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

45
        return null === $product->/** @scrutinizer ignore-call */ getProductType() ? null : $product->getProductType()->getName();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
    }
47
}
48