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

PutVariantBasedConfigurableItemToCartRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A fromArray() 4 4 1
A fromRequest() 4 4 1
A getCommand() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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