Completed
Pull Request — master (#206)
by Łukasz
03:09
created

PutSimpleItemToCartRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 1
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
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