ShippingMethodViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory;
6
7
use Setono\SyliusLagersystemPlugin\View\ShippingMethodView;
8
use Sylius\Component\Core\Model\ShipmentInterface;
9
use Webmozart\Assert\Assert;
10
11
class ShippingMethodViewFactory implements ShippingMethodViewFactoryInterface
12
{
13
    /** @var string */
14
    protected $shippingMethodViewClass;
15
16
    public function __construct(
17
        string $shippingMethodViewClass
18
    ) {
19
        $this->shippingMethodViewClass = $shippingMethodViewClass;
20
    }
21
22
    public function create(ShipmentInterface $shipment, string $locale): ShippingMethodView
23
    {
24
        $shippingMethod = $shipment->getMethod();
25
        Assert::notNull($shippingMethod);
26
27
        $translation = $shippingMethod->getTranslation($locale);
28
29
        /** @var ShippingMethodView $shippingMethodView */
30
        $shippingMethodView = new $this->shippingMethodViewClass();
31
        $shippingMethodView->code = $shippingMethod->getCode();
32
        $shippingMethodView->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

32
        /** @scrutinizer ignore-call */ 
33
        $shippingMethodView->name = $translation->getName();
Loading history...
33
        $shippingMethodView->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

33
        /** @scrutinizer ignore-call */ 
34
        $shippingMethodView->description = $translation->getDescription();
Loading history...
34
35
        return $shippingMethodView;
36
    }
37
}
38