Passed
Pull Request — master (#1)
by Igor
04:49
created

ProductVariantViewFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory\Product;
6
7
use Setono\SyliusLagersystemPlugin\View\Product\ProductVariantView;
8
use Sylius\Component\Core\Model\ProductVariantInterface;
9
10
final class ProductVariantViewFactory implements ProductVariantViewFactoryInterface
11
{
12
    /** @var string */
13
    private $productVariantViewClass;
14
15
    public function __construct(string $productVariantViewClass)
16
    {
17
        $this->productVariantViewClass = $productVariantViewClass;
18
    }
19
20
    public function create(ProductVariantInterface $variant, string $localeCode): ProductVariantView
21
    {
22
        $translation = $variant->getTranslation($localeCode);
23
24
        /** @var ProductVariantView $variantView */
25
        $variantView = new $this->productVariantViewClass();
26
        $variantView->id = $variant->getId();
27
        $variantView->code = $variant->getCode();
28
        $variantView->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

28
        /** @scrutinizer ignore-call */ 
29
        $variantView->name = $translation->getName();
Loading history...
29
        $variantView->weight = (int) ceil(1000 * $variant->getShippingWeight());
30
        $variantView->onHand = $variant->getOnHand();
31
32
        return $variantView;
33
    }
34
}
35