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

MePasswordChangeRequest::getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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\ResourceResponse;
13
use Psr\Http\Message\ResponseInterface;
14
use Commercetools\Core\Model\Customer\Customer;
15
use Commercetools\Core\Response\ApiResponseInterface;
16
17
/**
18
 * @package Commercetools\Core\Request\Me
19
 * @method Customer mapResponse(ApiResponseInterface $response)
20
 */
21
class MePasswordChangeRequest extends AbstractApiRequest
22
{
23
    const ID = 'id';
24
    const VERSION = 'version';
25
    const CURRENT_PASSWORD = 'currentPassword';
26
    const NEW_PASSWORD = 'newPassword';
27
28
    protected $resultClass = '\Commercetools\Core\Model\Customer\Customer';
29
30
    /**
31
     * @var int
32
     */
33
    protected $version;
34
35
    /**
36
     * @var string
37
     */
38
    protected $currentPassword;
39
40
    /**
41
     * @var string
42
     */
43
    protected $newPassword;
44
45
    /**
46
     * @param string $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
     * @param int $version
48
     * @param string $currentPassword
49
     * @param string $newPassword
50
     * @param Context $context
51
     */
52 2 View Code Duplication
    public function __construct($version, $currentPassword, $newPassword, Context $context = null)
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54 2
        parent::__construct(MeEndpoint::endpoint(), $context);
55 2
        $this->setVersion($version);
56 2
        $this->currentPassword = $currentPassword;
57 2
        $this->newPassword = $newPassword;
58 2
    }
59
60
    /**
61
     * @return int
62
     */
63 2
    public function getVersion()
64
    {
65 2
        return $this->version;
66
    }
67
68
    /**
69
     * @param int $version
70
     * @return $this
71
     */
72 2
    public function setVersion($version)
73
    {
74 2
        $this->version = $version;
75
76 2
        return $this;
77
    }
78
79
    /**
80
     * @param int $version
81
     * @param string $currentPassword
82
     * @param string $newPassword
83
     * @param Context $context
84
     * @return static
85
     */
86 2
    public static function ofVersionAndPasswords(
87
        $version,
88
        $currentPassword,
89
        $newPassword,
90
        Context $context = null
91
    ) {
92 2
        return new static($version, $currentPassword, $newPassword, $context);
93
    }
94
95
    /**
96
     * @return string
97
     * @internal
98
     */
99 2
    protected function getPath()
100
    {
101 2
        return (string)$this->getEndpoint() . '/password' . $this->getParamString();
102
    }
103
104
    /**
105
     * @return JsonRequest
106
     * @internal
107
     */
108 2
    public function httpRequest()
109
    {
110
        $payload = [
111 2
            static::VERSION => $this->getVersion(),
112 2
            static::CURRENT_PASSWORD => $this->currentPassword,
113 2
            static::NEW_PASSWORD => $this->newPassword
114
        ];
115 2
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
116
    }
117
118
    /**
119
     * @param ResponseInterface $response
120
     * @return ResourceResponse
121
     * @internal
122
     */
123 2
    public function buildResponse(ResponseInterface $response)
124
    {
125 2
        return new ResourceResponse($response, $this, $this->getContext());
126
    }
127
}
128