Completed
Pull Request — master (#290)
by
unknown
36:49 queued 34:03
created

PutSimpleItemToCartRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

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