Completed
Push — develop ( e77623...3cc0f7 )
by Jens
09:01
created

MeEmailConfirmRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 57
loc 57
ccs 13
cts 13
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A ofToken() 4 4 1
A getPath() 4 4 1
A httpRequest() 7 7 1
A buildResponse() 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
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Request\Me;
7
8
use Commercetools\Core\Client\HttpMethod;
9
use Commercetools\Core\Client\JsonRequest;
10
use Commercetools\Core\Model\Common\Context;
11
use Commercetools\Core\Request\AbstractApiRequest;
12
use Commercetools\Core\Response\ApiResponseInterface;
13
use Commercetools\Core\Model\Customer\Customer;
14
use Commercetools\Core\Response\ResourceResponse;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @package Commercetools\Core\Request\Me
19
 * @link https://dev.commercetools.com/http-api-projects-me-profile.html#verify-customers-email
20
 * @method Customer mapResponse(ApiResponseInterface $response)
21
 */
22 View Code Duplication
class MeEmailConfirmRequest extends AbstractApiRequest
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...
23
{
24
    protected $resultClass = '\Commercetools\Core\Model\Customer\Customer';
25
26
    const TOKEN_VALUE = 'tokenValue';
27
28
    /**
29
     * @var string
30
     */
31
    protected $tokenValue;
32
33
    /**
34
     * @param string $tokenValue
35
     * @param Context $context
36
     */
37 1
    public function __construct($tokenValue, Context $context = null)
38
    {
39 1
        parent::__construct(MeEndpoint::endpoint(), $context);
40 1
        $this->tokenValue = $tokenValue;
41 1
    }
42
43
    /**
44
     * @param string $tokenValue
45
     * @param Context $context
46
     * @return static
47
     */
48 1
    public static function ofToken($tokenValue, Context $context = null)
49
    {
50 1
        return new static($tokenValue, $context);
51
    }
52
53
    /**
54
     * @return string
55
     * @internal
56
     */
57 1
    protected function getPath()
58
    {
59 1
        return (string)$this->getEndpoint() . '/email/confirm' .  $this->getParamString();
60
    }
61
62
    /**
63
     * @return JsonRequest
64
     * @internal
65
     */
66 1
    public function httpRequest()
67
    {
68
        $payload = [
69 1
            static::TOKEN_VALUE => $this->tokenValue,
70
        ];
71 1
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
72
    }
73
74 1
    public function buildResponse(ResponseInterface $response)
75
    {
76 1
        return new ResourceResponse($response, $this, $this->getContext());
77
    }
78
}
79