Completed
Push — master ( 92f2fd...10a92d )
by Paweł
20s
created

PutSimpleItemToCartRequest::fromRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Request;
4
5
use Sylius\ShopApiPlugin\Command\PutSimpleItemToCart;
6
use Symfony\Component\HttpFoundation\Request;
7
8
final class PutSimpleItemToCartRequest
9
{
10
    /**
11
     * @var string
12
     */
13
    private $token;
14
15
    /**
16
     * @var string
17
     */
18
    private $productCode;
19
20
    /**
21
     * @var int
22
     */
23
    private $quantity;
24
25
    private function __construct($token, $productCode, $quantity)
26
    {
27
        $this->token = $token;
28
        $this->productCode = $productCode;
29
        $this->quantity = $quantity;
30
    }
31
32
    public static function fromArray(array $item)
33
    {
34
        return new self($item['token'] ?? null, $item['productCode'] ?? null, $item['quantity'] ?? null);
35
    }
36
37
    public static function fromRequest(Request $request)
38
    {
39
        return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('quantity'));
40
    }
41
42
    /**
43
     * @return PutSimpleItemToCart
44
     */
45
    public function getCommand()
46
    {
47
        return new PutSimpleItemToCart($this->token, $this->productCode, $this->quantity);
48
    }
49
}
50