Passed
Pull Request — master (#1)
by Igor
04:25
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
use Webmozart\Assert\Assert;
10
11
class OrderViewFactory implements OrderViewFactoryInterface
12
{
13
    /** @var string */
14
    protected $orderViewClass;
15
16
    public function __construct(
17
        string $orderViewClass
18
    ) {
19
        $this->orderViewClass = $orderViewClass;
20
    }
21
22
    public function create(OrderInterface $order): OrderView
23
    {
24
        $channel = $order->getChannel();
25
        Assert::notNull($channel);
26
27
        $locale = $channel->getDefaultLocale();
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

27
        /** @scrutinizer ignore-call */ 
28
        $locale = $channel->getDefaultLocale();
Loading history...
28
        Assert::notNull($locale);
29
30
        $checkoutCompletedAt = $order->getCheckoutCompletedAt();
31
        Assert::notNull($checkoutCompletedAt);
32
33
        /** @var OrderView $orderView */
34
        $orderView = new $this->orderViewClass();
35
        $orderView->id = $order->getId();
36
        $orderView->number = $order->getNumber();
37
        $orderView->channel = $channel->getCode();
38
        $orderView->currencyCode = $order->getCurrencyCode();
39
        $orderView->localeCode = $locale->getCode();
40
        $orderView->state = $order->getPaymentState();
41
        $orderView->checkoutState = $order->getCheckoutState();
42
        $orderView->checkoutCompletedAt = $checkoutCompletedAt->format('c');
43
        $orderView->paymentState = $order->getPaymentState();
44
45
        return $orderView;
46
    }
47
}
48