1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Review; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
10
|
|
|
use Commercetools\Core\Model\State\StateReference; |
11
|
|
|
use Commercetools\Core\Model\Common\ResourceIdentifier; |
12
|
|
|
use Commercetools\Core\Model\Customer\CustomerReference; |
13
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package Commercetools\Core\Model\Review |
17
|
|
|
* @link https://dev.commercetools.com/http-api-projects-reviews.html#reviewdraft |
18
|
|
|
* @method string getKey() |
19
|
|
|
* @method ReviewDraft setKey(string $key = null) |
20
|
|
|
* @method string getUniquenessValue() |
21
|
|
|
* @method ReviewDraft setUniquenessValue(string $uniquenessValue = null) |
22
|
|
|
* @method string getLocale() |
23
|
|
|
* @method ReviewDraft setLocale(string $locale = null) |
24
|
|
|
* @method string getAuthorName() |
25
|
|
|
* @method ReviewDraft setAuthorName(string $authorName = null) |
26
|
|
|
* @method string getTitle() |
27
|
|
|
* @method ReviewDraft setTitle(string $title = null) |
28
|
|
|
* @method string getText() |
29
|
|
|
* @method ReviewDraft setText(string $text = null) |
30
|
|
|
* @method ResourceIdentifier getTarget() |
31
|
|
|
* @method ReviewDraft setTarget(ResourceIdentifier $target = null) |
32
|
|
|
* @method StateReference getState() |
33
|
|
|
* @method ReviewDraft setState(StateReference $state = null) |
34
|
|
|
* @method int getRating() |
35
|
|
|
* @method ReviewDraft setRating(int $rating = null) |
36
|
|
|
* @method CustomerReference getCustomer() |
37
|
|
|
* @method ReviewDraft setCustomer(CustomerReference $customer = null) |
38
|
|
|
* @method CustomFieldObject getCustom() |
39
|
|
|
* @method ReviewDraft setCustom(CustomFieldObject $custom = null) |
40
|
|
|
*/ |
41
|
|
|
class ReviewDraft extends JsonObject |
42
|
|
|
{ |
43
|
16 |
|
public function fieldDefinitions() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
16 |
|
'key' => [static::TYPE => 'string'], |
47
|
16 |
|
'uniquenessValue' => [static::TYPE => 'string'], |
48
|
16 |
|
'locale' => [static::TYPE => 'string'], |
49
|
16 |
|
'authorName' => [static::TYPE => 'string'], |
50
|
16 |
|
'title' => [static::TYPE => 'string'], |
51
|
16 |
|
'text' => [static::TYPE => 'string'], |
52
|
16 |
|
'target' => [static::TYPE => ResourceIdentifier::class], |
53
|
16 |
|
'state' => [static::TYPE => StateReference::class], |
54
|
16 |
|
'rating' => [static::TYPE => 'int'], |
55
|
16 |
|
'customer' => [static::TYPE => CustomerReference::class], |
56
|
16 |
|
'custom' => [static::TYPE => CustomFieldObject::class], |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $title |
62
|
|
|
* @param Context|callable $context |
63
|
|
|
* @return ReviewDraft |
64
|
|
|
*/ |
65
|
16 |
|
public static function ofTitle($title, $context = null) |
66
|
|
|
{ |
67
|
16 |
|
return static::of($context)->setTitle($title); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $text |
72
|
|
|
* @param Context|callable $context |
73
|
|
|
* @return ReviewDraft |
74
|
|
|
*/ |
75
|
|
|
public static function ofText($text, $context = null) |
76
|
|
|
{ |
77
|
|
|
return static::of($context)->setText($text); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $rating |
82
|
|
|
* @param Context|callable $context |
83
|
|
|
* @return ReviewDraft |
84
|
|
|
*/ |
85
|
|
|
public static function ofRating($rating, $context = null) |
86
|
|
|
{ |
87
|
|
|
return static::of($context)->setRating($rating); |
88
|
|
|
} |
89
|
|
|
|
90
|
16 |
View Code Duplication |
public function jsonSerialize() |
|
|
|
|
91
|
|
|
{ |
92
|
16 |
|
$data = parent::jsonSerialize(); |
93
|
16 |
|
if (isset($data['locale'])) { |
94
|
|
|
$data['locale'] = str_replace('_', '-', $data['locale']); |
95
|
|
|
} |
96
|
16 |
|
return $data; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.