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

OrderViewFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLagersystemPlugin\Factory\Order;
6
7
use Setono\SyliusLagersystemPlugin\View\Order\OrderView;
8
use Sylius\Component\Core\Model\OrderInterface;
9
10
class OrderViewFactory implements OrderViewFactoryInterface
11
{
12
    /** @var string */
13
    protected $orderViewClass;
14
15
    public function __construct(
16
        string $orderViewClass
17
    ) {
18
        $this->orderViewClass = $orderViewClass;
19
    }
20
21
    public function create(OrderInterface $order): OrderView
22
    {
23
        /** @var OrderView $orderView */
24
        $orderView = new $this->orderViewClass();
25
        $orderView->id = $order->getId();
26
        $orderView->number = $order->getNumber();
27
        $orderView->channel = $order->getChannel()->getCode();
28
        $orderView->currencyCode = $order->getCurrencyCode();
29
        $orderView->localeCode = $order->getChannel()->getDefaultLocale()->getCode();
0 ignored issues
show
Bug introduced by
The method getDefaultLocale() does not exist on Sylius\Component\Channel\Model\ChannelInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Channel\Model\Channel. 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

29
        $orderView->localeCode = $order->getChannel()->/** @scrutinizer ignore-call */ getDefaultLocale()->getCode();
Loading history...
30
        $orderView->state = $order->getPaymentState();
31
        $orderView->checkoutState = $order->getCheckoutState();
32
        $orderView->checkoutCompletedAt = $order->getCheckoutCompletedAt()->format('c');
33
        $orderView->paymentState = $order->getPaymentState();
34
35
        return $orderView;
36
    }
37
}
38