1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\CustomField; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
10
|
|
|
use Commercetools\Core\Model\Type\TypeReference; |
11
|
|
|
use Commercetools\Core\Model\Common\ResourceIdentifier; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @package Commercetools\Core\Model\CustomField |
15
|
|
|
* @link https://dev.commercetools.com/http-api-projects-custom-fields.html#new-custom-fields |
16
|
|
|
* @method FieldContainer getFields() |
17
|
|
|
* @method CustomFieldObjectDraft setFields(FieldContainer $fields = null) |
18
|
|
|
* @method TypeReference getType() |
19
|
|
|
* @method CustomFieldObjectDraft setType(TypeReference $type = null) |
20
|
|
|
*/ |
21
|
|
|
class CustomFieldObjectDraft extends JsonObject |
22
|
|
|
{ |
23
|
4 |
View Code Duplication |
public function fieldDefinitions() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
4 |
|
'type' => [static::TYPE => '\Commercetools\Core\Model\Type\TypeReference'], |
27
|
4 |
|
'fields' => [static::TYPE => '\Commercetools\Core\Model\CustomField\FieldContainer'] |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param $typeKey |
33
|
|
|
* @param Context|callable $context |
34
|
|
|
* @return CustomFieldObjectDraft |
35
|
|
|
*/ |
36
|
|
|
public static function ofTypeKey($typeKey, $context = null) |
37
|
|
|
{ |
38
|
|
|
$draft = static::of($context)->setType(TypeReference::ofKey($typeKey)); |
39
|
|
|
|
40
|
|
|
return $draft; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $typeId |
45
|
|
|
* @param Context|callable $context |
46
|
|
|
* @return CustomFieldObjectDraft |
47
|
|
|
*/ |
48
|
|
|
public static function ofTypeId($typeId, $context = null) |
49
|
|
|
{ |
50
|
|
|
$draft = static::of($context)->setType(TypeReference::ofId($typeId)); |
51
|
|
|
|
52
|
|
|
return $draft; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param TypeReference $type |
57
|
|
|
* @param Context|callable $context |
58
|
|
|
* @return CustomFieldObjectDraft |
59
|
|
|
*/ |
60
|
4 |
|
public static function ofType(TypeReference $type, $context = null) |
61
|
|
|
{ |
62
|
4 |
|
$draft = static::of($context)->setType($type); |
63
|
|
|
|
64
|
4 |
|
return $draft; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.