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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

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