Passed
Push — master ( 0d508a...6e2a06 )
by Jens
16:22 queued 10s
created

OrderEditUpdateByKeyRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 4
crap 1
1
<?php
2
/**
3
 */
4
5
namespace Commercetools\Core\Request\OrderEdits;
6
7
use Commercetools\Core\Client\HttpMethod;
8
use Commercetools\Core\Client\JsonRequest;
9
use Commercetools\Core\Model\Common\Context;
10
use Commercetools\Core\Model\OrderEdit\OrderEdit;
11
use Commercetools\Core\Request\AbstractUpdateByKeyRequest;
12
use Commercetools\Core\Response\ApiResponseInterface;
13
use Commercetools\Core\Model\MapperInterface;
14
15
/**
16
 * @package Commercetools\Core\Request\OrderEdits
17
 *
18
 * @method OrderEdit mapResponse(ApiResponseInterface $response)
19
 * @method OrderEdit mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
20
 */
21
class OrderEditUpdateByKeyRequest extends AbstractUpdateByKeyRequest
22
{
23
    const DRY_RUN = 'dryRun';
24
25
    protected $resultClass = OrderEdit::class;
26
27
    protected $dryRun = false;
28
29
    /**
30
     * @param bool $dryRun
31
     * @return OrderEditUpdateByKeyRequest
32
     */
33 1
    public function setDryRun($dryRun)
34
    {
35 1
        $this->dryRun = $dryRun;
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * @param string $key
42
     * @param int $version
43
     * @param array $actions
44
     * @param Context $context
45
     */
46 4
    public function __construct($key, $version, array $actions = [], Context $context = null)
47
    {
48 4
        parent::__construct(OrderEditsEndpoint::endpoint(), $key, $version, $actions, $context);
49 4
    }
50
51
    /**
52
     * @param string $key
53
     * @param int $version
54
     * @param Context $context
55
     * @return static
56
     */
57 4
    public static function ofKeyAndVersion($key, $version, Context $context = null)
58
    {
59 4
        return new static($key, $version, [], $context);
60
    }
61
62
    /**
63
     * @return JsonRequest
64
     * @internal
65
     */
66 1
    public function httpRequest()
67
    {
68
        $payload = [
69 1
            static::VERSION => $this->getVersion(),
70 1
            static::ACTIONS => $this->getActions(),
71 1
            static::DRY_RUN => $this->dryRun
72
        ];
73 1
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
74
    }
75
}
76