Passed
Pull Request — master (#40)
by
unknown
05:06
created

MealVoucherResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMealVoucherCategory() 0 6 2
A resolve() 0 7 2
A getMealVoucherFromItem() 0 9 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
 * 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\Resolver;
14
15
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface;
16
use BitBag\SyliusMolliePlugin\Payments\Methods\MealVoucher;
17
use Sylius\Component\Core\Model\OrderItemInterface;
18
19
final class MealVoucherResolver implements MealVoucherResolverInterface
20
{
21
    public function resolve(MollieGatewayConfigInterface $method, OrderItemInterface $item): ?string
22
    {
23
        if ($method->getMethodId() === MealVoucher::MEAL_VOUCHERS) {
0 ignored issues
show
Bug introduced by
The method getMethodId() does not exist on BitBag\SyliusMolliePlugi...eGatewayConfigInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to BitBag\SyliusMolliePlugi...eGatewayConfigInterface. ( Ignorable by Annotation )

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

23
        if ($method->/** @scrutinizer ignore-call */ getMethodId() === MealVoucher::MEAL_VOUCHERS) {
Loading history...
24
            return $this->getMealVoucherCategory($method, $item);
25
        }
26
27
        return null;
28
    }
29
30
    private function getMealVoucherCategory(MollieGatewayConfigInterface $method, OrderItemInterface $item): string
31
    {
32
        if (null === $method->getDefaultCategory()) {
0 ignored issues
show
Bug introduced by
The method getDefaultCategory() does not exist on BitBag\SyliusMolliePlugi...eGatewayConfigInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to BitBag\SyliusMolliePlugi...eGatewayConfigInterface. ( Ignorable by Annotation )

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

32
        if (null === $method->/** @scrutinizer ignore-call */ getDefaultCategory()) {
Loading history...
33
            return $this->getMealVoucherFromItem($item);
34
        } else {
35
            return $method->getDefaultCategory()->getName();
36
        }
37
    }
38
39
    private function getMealVoucherFromItem(OrderItemInterface $item): string
40
    {
41
        $product = $item->getProduct();
42
43
        if (null === $product->getProductType()) {
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

43
        if (null === $product->/** @scrutinizer ignore-call */ getProductType()) {

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...
44
            throw new \LogicException(\sprintf('No product category found in product name %s', $product->getName()));
45
        }
46
47
        return $product->getProductType()->getName();
48
    }
49
}
50