Passed
Pull Request — master (#40)
by
unknown
04:48
created

MealVoucherResolver::getMealVoucherFromItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
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, array $details): ?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
            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

24
            if (null === $method->/** @scrutinizer ignore-call */ getDefaultCategory()) {
Loading history...
25
                return $this->getMealVoucherFromItem($item);
26
            } else {
27
                return $method->getDefaultCategory()->getName();
28
            }
29
        }
30
31
        return null;
32
    }
33
34
    private function getMealVoucherFromItem(OrderItemInterface $item)
35
    {
36
        $product = $item->getProduct();
37
38
        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

38
        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...
39
            throw new \LogicException(\sprintf('No product category found in product name %s', $product->getName()));
40
        }
41
42
        return $product->getProductType()->getName();
43
    }
44
}
45