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

fromRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
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\PutVariantBasedConfigurableItemToCart;
6
use Symfony\Component\HttpFoundation\Request;
7
8 View Code Duplication
final class PutVariantBasedConfigurableItemToCartRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * @var string
12
     */
13
    private $token;
14
15
    /**
16
     * @var string
17
     */
18
    private $productCode;
19
20
    /**
21
     * @var string
22
     */
23
    private $variantCode;
24
25
    /**
26
     * @var int
27
     */
28
    private $quantity;
29
30
    private function __construct($token, $productCode, $variantCode, $quantity)
31
    {
32
        $this->token = $token;
33
        $this->productCode = $productCode;
34
        $this->variantCode = $variantCode;
35
        $this->quantity = $quantity;
36
    }
37
38
    public static function fromArray(array $item)
39
    {
40
        return new self($item['token'] ?? null, $item['productCode'] ?? null, $item['variantCode'] ?? null, $item['quantity'] ?? null);
41
    }
42
43
    public static function fromRequest(Request $request)
44
    {
45
        return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('variantCode'), $request->request->get('quantity'));
46
    }
47
48
    /**
49
     * @return PutVariantBasedConfigurableItemToCart
50
     */
51
    public function getCommand()
52
    {
53
        return new PutVariantBasedConfigurableItemToCart($this->token, $this->productCode, $this->variantCode, $this->quantity);
54
    }
55
}
56