Passed
Push — develop ( 8a9b30...fbd41a )
by Jens
18:38 queued 13s
created

CustomObjectRequestBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 14
c 1
b 0
f 1
dl 0
loc 76
ccs 18
cts 20
cp 0.9
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 3 1
A create() 0 4 1
A query() 0 4 1
A getById() 0 4 1
A delete() 0 4 1
A deleteByContainerAndKey() 0 4 1
A getByContainerAndKey() 0 4 1
1
<?php
2
// phpcs:disable Generic.Files.LineLength
3
namespace Commercetools\Core\Builder\Request;
4
5
use Commercetools\Core\Request\CustomObjects\CustomObjectByIdGetRequest;
6
use Commercetools\Core\Request\CustomObjects\CustomObjectByKeyGetRequest;
7
use Commercetools\Core\Request\CustomObjects\CustomObjectCreateRequest;
8
use Commercetools\Core\Model\CustomObject\CustomObjectDraft;
9
use Commercetools\Core\Request\CustomObjects\CustomObjectDeleteByKeyRequest;
10
use Commercetools\Core\Request\CustomObjects\CustomObjectDeleteRequest;
11
use Commercetools\Core\Model\CustomObject\CustomObject;
12
use Commercetools\Core\Request\CustomObjects\CustomObjectQueryRequest;
13
14
class CustomObjectRequestBuilder
15
{
16
17
    /**
18
     *
19
     * @param string $id
20
     * @return CustomObjectByIdGetRequest
21
     */
22 2
    public function getById($id)
23
    {
24 2
        $request = CustomObjectByIdGetRequest::ofId($id);
25 2
        return $request;
26
    }
27
28
    /**
29
     * @link https://docs.commercetools.com/http-api-projects-custom-objects.html#get-customobject-by-container-and-key
30
     * @param string $container
31
     * @param string $key
32
     * @return CustomObjectByKeyGetRequest
33
     */
34 2
    public function getByContainerAndKey($container, $key)
35
    {
36 2
        $request = CustomObjectByKeyGetRequest::ofContainerAndKey($container, $key);
37 2
        return $request;
38
    }
39
40
    /**
41
     * @link https://docs.commercetools.com/http-api-projects-custom-objects.html#create-a-customobject
42
     * @param CustomObjectDraft|CustomObject $customObject
43
     * @return CustomObjectCreateRequest
44
     */
45 6
    public function create($customObject)
46
    {
47 6
        $request = CustomObjectCreateRequest::ofObject($customObject);
48 5
        return $request;
49
    }
50
51
    /**
52
     * @link https://docs.commercetools.com/http-api-projects-custom-objects.html#delete-customobject-by-container-and-key
53
     * @param CustomObject $customObject
54
     * @return CustomObjectDeleteByKeyRequest
55
     */
56 1
    public function deleteByContainerAndKey(CustomObject $customObject)
57
    {
58 1
        $request = CustomObjectDeleteByKeyRequest::ofContainerAndKey($customObject->getContainer(), $customObject->getKey());
59 1
        return $request;
60
    }
61
62
    /**
63
     * @link https://docs.commercetools.com/http-api-projects-custom-objects.html#delete-customobject-by-id
64
     * @param CustomObject $customObject
65
     * @return CustomObjectDeleteRequest
66
     */
67 1
    public function delete(CustomObject $customObject)
68
    {
69 1
        $request = CustomObjectDeleteRequest::ofIdAndVersion($customObject->getId(), $customObject->getVersion());
70 1
        return $request;
71
    }
72
73
    /**
74
     * @link https://docs.commercetools.com/http-api-projects-custom-objects.html#query-customobjects
75
     *
76
     * @return CustomObjectQueryRequest
77
     */
78 2
    public function query()
79
    {
80 2
        $request = CustomObjectQueryRequest::of();
81 2
        return $request;
82
    }
83
84
    /**
85
     * @return CustomObjectRequestBuilder
86
     */
87
    public function of()
88
    {
89
        return new self();
90
    }
91
}
92