Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 76199f4

Browse files
author
Jens Schulze
committed
chore(Annotation): add correct typed magic getReference method to resource models
1 parent 6029a02 commit 76199f4

File tree

18 files changed

+40
-0
lines changed

18 files changed

+40
-0
lines changed

src/Helper/Annotate/ClassAnnotator.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ protected function reflectFields()
7272
}
7373
}
7474

75+
protected function reflectReference()
76+
{
77+
$reflectionClass = new \ReflectionClass($this->class->getClassName());
78+
if (!$reflectionClass->isSubclassOf('Commercetools\Core\Model\Common\Resource')) {
79+
return;
80+
}
81+
82+
$referenceClass = $this->class->getClassName() . 'Reference';
83+
$referenceShortName = $this->class->getShortClassName() . 'Reference';
84+
if (class_exists($referenceClass)) {
85+
$this->class->addMagicMethod(
86+
'getReference',
87+
[],
88+
$referenceShortName,
89+
null,
90+
null,
91+
false,
92+
true
93+
);
94+
}
95+
}
96+
7597
protected function reflectElementType()
7698
{
7799
$reflectionClass = new \ReflectionClass($this->class->getClassName());
@@ -163,6 +185,7 @@ public function generate()
163185
}
164186

165187
$this->reflectFields();
188+
$this->reflectReference();
166189
$this->annotate();
167190
}
168191

src/Model/Cart/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* @method Cart setCustom(CustomFieldObject $custom = null)
5858
* @method PaymentInfo getPaymentInfo()
5959
* @method Cart setPaymentInfo(PaymentInfo $paymentInfo = null)
60+
* @method CartReference getReference()
6061
*/
6162
class Cart extends Resource
6263
{

src/Model/CartDiscount/CartDiscount.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* @method CartDiscount setRequiresDiscountCode(bool $requiresDiscountCode = null)
4444
* @method ReferenceCollection getReferences()
4545
* @method CartDiscount setReferences(ReferenceCollection $references = null)
46+
* @method CartDiscountReference getReference()
4647
*/
4748
class CartDiscount extends Resource
4849
{

src/Model/Category/Category.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* @method Category setMetaTitle(LocalizedString $metaTitle = null)
4444
* @method LocalizedString getMetaKeywords()
4545
* @method Category setMetaKeywords(LocalizedString $metaKeywords = null)
46+
* @method CategoryReference getReference()
4647
*/
4748
class Category extends Resource
4849
{

src/Model/Channel/Channel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @method Channel setCustom(CustomFieldObject $custom = null)
3535
* @method ReviewRatingStatistics getReviewRatingStatistics()
3636
* @method Channel setReviewRatingStatistics(ReviewRatingStatistics $reviewRatingStatistics = null)
37+
* @method ChannelReference getReference()
3738
*/
3839
class Channel extends Resource
3940
{

src/Model/Customer/Customer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* @method Customer setCustomerGroup(CustomerGroupReference $customerGroup = null)
5858
* @method CustomFieldObject getCustom()
5959
* @method Customer setCustom(CustomFieldObject $custom = null)
60+
* @method CustomerReference getReference()
6061
*/
6162
class Customer extends Resource
6263
{

src/Model/CustomerGroup/CustomerGroup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @method CustomerGroup setLastModifiedAt(\DateTime $lastModifiedAt = null)
2222
* @method string getName()
2323
* @method CustomerGroup setName(string $name = null)
24+
* @method CustomerGroupReference getReference()
2425
*/
2526
class CustomerGroup extends Resource
2627
{

src/Model/DiscountCode/DiscountCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* @method DiscountCode setMaxApplications(int $maxApplications = null)
4141
* @method int getMaxApplicationsPerCustomer()
4242
* @method DiscountCode setMaxApplicationsPerCustomer(int $maxApplicationsPerCustomer = null)
43+
* @method DiscountCodeReference getReference()
4344
*/
4445
class DiscountCode extends Resource
4546
{

src/Model/Order/Order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
* @method Order setState(StateReference $state = null)
8080
* @method PaymentInfo getPaymentInfo()
8181
* @method Order setPaymentInfo(PaymentInfo $paymentInfo = null)
82+
* @method OrderReference getReference()
8283
*/
8384
class Order extends Resource
8485
{

src/Model/Payment/Payment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @method Payment setTransactions(TransactionCollection $transactions = null)
5050
* @method CustomFieldObjectCollection getInterfaceInteractions()
5151
* @method Payment setInterfaceInteractions(CustomFieldObjectCollection $interfaceInteractions = null)
52+
* @method PaymentReference getReference()
5253
*/
5354
class Payment extends Resource
5455
{

0 commit comments

Comments
 (0)