PaymentMethodViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory;
6
7
use Setono\SyliusLagersystemPlugin\View\PaymentMethodView;
8
use Sylius\Component\Core\Model\PaymentMethodInterface;
9
10
class PaymentMethodViewFactory implements PaymentMethodViewFactoryInterface
11
{
12
    /** @var string */
13
    protected $paymentMethodViewClass;
14
15
    public function __construct(string $paymentMethodViewClass)
16
    {
17
        $this->paymentMethodViewClass = $paymentMethodViewClass;
18
    }
19
20
    public function create(PaymentMethodInterface $paymentMethod, string $locale): PaymentMethodView
21
    {
22
        $translation = $paymentMethod->getTranslation($locale);
23
24
        /** @var PaymentMethodView $paymentMethodView */
25
        $paymentMethodView = new $this->paymentMethodViewClass();
26
        $paymentMethodView->code = $paymentMethod->getCode() ?? '';
27
        $paymentMethodView->name = $translation->getName() ?? '';
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Sylius\Component\Resourc...el\TranslationInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Resourc...del\AbstractTranslation or Sylius\Component\Product...lueTranslationInterface or spec\Sylius\Component\Re...del\ConcreteTranslation or Sylius\Component\Product...tOptionValueTranslation or AppBundle\Entity\BookTranslation or Sylius\Component\Product...tOptionValueTranslation. Are you sure you never get one of those? ( Ignorable by Annotation )

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

27
        $paymentMethodView->name = $translation->/** @scrutinizer ignore-call */ getName() ?? '';
Loading history...
28
        $paymentMethodView->description = $translation->getDescription() ?? '';
0 ignored issues
show
Bug introduced by
The method getDescription() does not exist on Sylius\Component\Resourc...el\TranslationInterface. It seems like you code against a sub-type of Sylius\Component\Resourc...el\TranslationInterface such as Sylius\Component\Product...uctTranslationInterface or Sylius\Component\Taxonom...xonTranslationInterface or Sylius\Component\Shippin...hodTranslationInterface or Sylius\Component\Payment...hodTranslationInterface or Sylius\Component\Taxonomy\Model\TaxonTranslation or Sylius\Component\Shippin...ippingMethodTranslation or Sylius\Component\Payment...aymentMethodTranslation or Sylius\Component\Product\Model\ProductTranslation. ( Ignorable by Annotation )

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

28
        $paymentMethodView->description = $translation->/** @scrutinizer ignore-call */ getDescription() ?? '';
Loading history...
29
30
        return $paymentMethodView;
31
    }
32
}
33