Skip to content

Commit aa3a918

Browse files
committed
Run rector
1 parent 22f7fce commit aa3a918

File tree

60 files changed

+128
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+128
-245
lines changed

src/adjusters/Discount.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ public function adjust(Order $order): array
173173
}, SORT_DESC);
174174

175175
// Remove non-promotable line items
176-
$lineItemsByPrice = ArrayHelper::where($lineItemsByPrice, function(LineItem $lineItem) {
177-
return $lineItem->getIsPromotable();
178-
}, true, true);
176+
$lineItemsByPrice = ArrayHelper::where($lineItemsByPrice, fn(LineItem $lineItem) => $lineItem->getIsPromotable(), true, true);
179177

180178
// Loop over each order level adjustment and add an adjustment to each line item until it runs out.
181179
foreach ($orderLevelAdjustments as $orderLevelAdjustment) {

src/base/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function getConfig(): array
233233
$configData = [
234234
'name' => $this->name,
235235
'handle' => $this->handle,
236-
'type' => get_class($this),
236+
'type' => static::class,
237237
'settings' => $this->getSettings(),
238238
'sortOrder' => ($this->sortOrder ?? 99),
239239
'paymentType' => $this->paymentType,

src/behaviors/CurrencyAttributeBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CurrencyAttributeBehavior extends Behavior
6868
* @uses setDefaultCurrency()
6969
* @uses getDefaultCurrency()
7070
*/
71-
private ?string $_defaultCurrency;
71+
private ?string $_defaultCurrency = null;
7272

7373
/**
7474
* @var array mapping of attribute => currency if the default is not desired

src/collections/InventoryMovementCollection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class InventoryMovementCollection extends Collection
2929
*/
3030
public function getPurchasables(): array
3131
{
32-
return $this->map(function(InventoryMovementInterface $updateInventoryLevel) {
33-
return $updateInventoryLevel->getInventoryItem()->getPurchasable();
34-
})->all();
32+
return $this->map(fn(InventoryMovementInterface $updateInventoryLevel) => $updateInventoryLevel->getInventoryItem()->getPurchasable())->all();
3533
}
3634
}

src/collections/UpdateInventoryLevelCollection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public static function make($items = [])
4747
*/
4848
public function getPurchasables(): array
4949
{
50-
return $this->map(function(UpdateInventoryLevel|UpdateInventoryLevelInTransfer $updateInventoryLevel) {
51-
return $updateInventoryLevel->getInventoryItem()->getPurchasable();
52-
})->filter()->all();
50+
return $this->map(fn(UpdateInventoryLevel|UpdateInventoryLevelInTransfer $updateInventoryLevel) => $updateInventoryLevel->getInventoryItem()->getPurchasable())->filter()->all();
5351
}
5452
}

src/controllers/CatalogPricingRulesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function actionEdit(?string $storeHandle = null, int $id = null, CatalogP
8686
$store = Plugin::getInstance()->getStores()->getStoreByHandle($storeHandle);
8787
}
8888

89-
$store = $store ?? Plugin::getInstance()->getStores()->getPrimaryStore();
89+
$store ??= Plugin::getInstance()->getStores()->getPrimaryStore();
9090

9191
$variables = compact('id', 'catalogPricingRule', 'storeHandle');
9292

@@ -326,7 +326,7 @@ public function actionUpdateStatus(): void
326326

327327
/** @var CatalogPricingRuleRecord $rule */
328328
foreach ($rules as $rule) {
329-
$storeId = $storeId ?? $rule->storeId;
329+
$storeId ??= $rule->storeId;
330330
$rule->enabled = ($status == 'enabled');
331331
$rule->save();
332332
}

src/controllers/InventoryController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,7 @@ public function actionEditUpdateLevelsModal(): Response
575575
'inventoryItemIds' => $inventoryItemIds,
576576
'inventoryLevels' => $inventoryLevels,
577577
'updateAction' => $updateAction,
578-
'inventoryLocationOptions' => Plugin::getInstance()->getInventoryLocations()->getAllInventoryLocations()->mapWithKeys(function($location) {
579-
return [$location->id => $location->getUiLabel()];
580-
})->all(),
578+
'inventoryLocationOptions' => Plugin::getInstance()->getInventoryLocations()->getAllInventoryLocations()->mapWithKeys(fn($location) => [$location->id => $location->getUiLabel()])->all(),
581579
'type' => $type,
582580
'quantity' => $quantity,
583581
'note' => $note,

src/controllers/OrdersController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,9 @@ public function actionGetCustomerAddresses(): Response
819819

820820
$total = $addressElements->count();
821821

822-
$addresses = $addressElements->map(function(Address $address) {
823-
return $address->toArray() + [
824-
'html' => Cp::elementCardHtml($address),
825-
];
826-
});
822+
$addresses = $addressElements->map(fn(Address $address) => $address->toArray() + [
823+
'html' => Cp::elementCardHtml($address),
824+
]);
827825

828826
return $this->asSuccess(data: compact('addresses', 'total'));
829827
}

src/controllers/SettingsController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ public function actionSites(): Response
8585
'sites' => $sites,
8686
'primaryStoreId' => Plugin::getInstance()->getStores()->getPrimaryStore()->id,
8787
'stores' => Plugin::getInstance()->getStores()->getAllStores(),
88-
'storesList' => Plugin::getInstance()->getStores()->getAllStores()->map(function($store) {
89-
return [
90-
'label' => $store->name . ($store->primary ? ' (' . Craft::t('commerce', 'Primary') . ')' : ''),
91-
'value' => $store->id,
92-
];
93-
}),
88+
'storesList' => Plugin::getInstance()->getStores()->getAllStores()->map(fn($store) => [
89+
'label' => $store->name . ($store->primary ? ' (' . Craft::t('commerce', 'Primary') . ')' : ''),
90+
'value' => $store->id,
91+
]),
9492
]);
9593
}
9694

src/controllers/ShippingCategoriesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function actionEdit(?string $storeHandle = null, int $id = null, Shipping
6565
$store = Plugin::getInstance()->getStores()->getStoreByHandle($storeHandle);
6666
}
6767

68-
$store = $store ?? Plugin::getInstance()->getStores()->getPrimaryStore();
68+
$store ??= Plugin::getInstance()->getStores()->getPrimaryStore();
6969

7070
if (!$variables['shippingCategory']) {
7171
if ($variables['id']) {

src/controllers/TransfersController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ public function actionRenderManagement(): string
326326
$details = $this->request->getParam('details', []);
327327

328328
if ($this->request->getParam('removeInventoryItemUid')) {
329-
$details = array_filter($details, function($detail) {
330-
return $detail['uid'] !== $this->request->getParam('removeInventoryItemUid');
331-
});
329+
$details = array_filter($details, fn($detail) => $detail['uid'] !== $this->request->getParam('removeInventoryItemUid'));
332330
}
333331
$transfer->setDetails($details);
334332

src/elements/Order.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,15 +2755,11 @@ public function getTotalPaid(): float
27552755

27562756
$transactions = collect($this->_transactions);
27572757

2758-
$paid = $transactions->filter(function($transaction) {
2759-
return $transaction->status == TransactionRecord::STATUS_SUCCESS
2760-
&& in_array($transaction->type, [TransactionRecord::TYPE_PURCHASE, TransactionRecord::TYPE_CAPTURE]);
2761-
})->sum('amount');
2762-
2763-
$refunded = $transactions->filter(function($transaction) {
2764-
return $transaction->status == TransactionRecord::STATUS_SUCCESS
2765-
&& $transaction->type == TransactionRecord::TYPE_REFUND;
2766-
})->sum('amount');
2758+
$paid = $transactions->filter(fn($transaction) => $transaction->status == TransactionRecord::STATUS_SUCCESS
2759+
&& in_array($transaction->type, [TransactionRecord::TYPE_PURCHASE, TransactionRecord::TYPE_CAPTURE]))->sum('amount');
2760+
2761+
$refunded = $transactions->filter(fn($transaction) => $transaction->status == TransactionRecord::STATUS_SUCCESS
2762+
&& $transaction->type == TransactionRecord::TYPE_REFUND)->sum('amount');
27672763

27682764
return (float)$this->getTeller()->subtract($paid, $refunded);
27692765
}

src/elements/Product.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,9 +1979,7 @@ protected function attributeHtml(string $attribute): string
19791979

19801980
if ($value->isNotEmpty() && $value->count() > 1) {
19811981
$otherItems = $value->filter(fn($v, $k) => $k > 0);
1982-
$otherHtml = $otherItems->map(function($v) {
1983-
return Cp::elementChipHtml($v);
1984-
})->join('');
1982+
$otherHtml = $otherItems->map(fn($v) => Cp::elementChipHtml($v))->join('');
19851983

19861984
$html .= Html::tag('span', '+' . Craft::$app->getFormatter()->asInteger($otherItems->count()), [
19871985
'title' => $otherItems->map(fn($v) => $v->title)->join(', '),

src/elements/Transfer.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,24 +369,12 @@ protected static function defineDefaultTableAttributes(string $source): array
369369
*/
370370
protected function attributeHtml(string $attribute): string
371371
{
372-
switch ($attribute) {
373-
case 'originLocation':
374-
{
375-
return $this->getOriginLocation()?->getUiLabel() ?? '';
376-
}
377-
case 'destinationLocation':
378-
{
379-
return $this->getDestinationLocation()?->getUiLabel() ?? '';
380-
}
381-
case 'received':
382-
{
383-
return $this->getTotalReceived() . '/' . $this->getTotalQuantity();
384-
}
385-
default:
386-
{
387-
return parent::attributeHtml($attribute);
388-
}
389-
}
372+
return match ($attribute) {
373+
'originLocation' => $this->getOriginLocation()?->getUiLabel() ?? '',
374+
'destinationLocation' => $this->getDestinationLocation()?->getUiLabel() ?? '',
375+
'received' => $this->getTotalReceived() . '/' . $this->getTotalQuantity(),
376+
default => parent::attributeHtml($attribute),
377+
};
390378
}
391379

392380
/**

src/elements/Variant.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,6 @@ public function getGqlTypeName(): string
971971
}
972972

973973
/**
974-
* @param mixed $context
975974
* @return string
976975
* @since 3.1
977976
*/
@@ -1302,9 +1301,7 @@ protected function availableShippingCategories(): array
13021301

13031302
// Limit to only those for this product type
13041303
$categoryIds = collect(Plugin::getInstance()->getShippingCategories()->getShippingCategoriesByProductTypeId($productTypeId))->pluck('id')->toArray();
1305-
$available = collect($allAvailableShippingCategories)->filter(function(ShippingCategory $category) use ($categoryIds) {
1306-
return in_array($category->id, $categoryIds);
1307-
});
1304+
$available = collect($allAvailableShippingCategories)->filter(fn(ShippingCategory $category) => in_array($category->id, $categoryIds));
13081305

13091306
if ($available->isEmpty()) {
13101307
return [Plugin::getInstance()->getShippingCategories()->getDefaultShippingCategory($this->storeId)];
@@ -1328,9 +1325,7 @@ protected function availableTaxCategories(): array
13281325

13291326
// Limit to only those for this product type
13301327
$categoryIds = collect(Plugin::getInstance()->getTaxCategories()->getTaxCategoriesByProductTypeId($productTypeId))->pluck('id')->toArray();
1331-
$available = collect($allAvailableTaxCategories)->filter(function(TaxCategory $category) use ($categoryIds) {
1332-
return in_array($category->id, $categoryIds);
1333-
});
1328+
$available = collect($allAvailableTaxCategories)->filter(fn(TaxCategory $category) => in_array($category->id, $categoryIds));
13341329

13351330
if ($available->isEmpty()) {
13361331
return [Plugin::getInstance()->getTaxCategories()->getDefaultTaxCategory()];

src/elements/VariantCollection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public static function make($items = [])
5151
*/
5252
public function cheapest(): ?Variant
5353
{
54-
return $this->reduce(function(?Variant $cheapest, Variant $variant) {
55-
return !$cheapest || $variant->getSalePrice() < $cheapest->getSalePrice() ? $variant : $cheapest;
56-
});
54+
return $this->reduce(fn(?Variant $cheapest, Variant $variant) => !$cheapest || $variant->getSalePrice() < $cheapest->getSalePrice() ? $variant : $cheapest);
5755
}
5856
}

src/elements/conditions/addresses/PostalCodeFormulaConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function matchElement(ElementInterface $element): bool
5959

6060
try {
6161
return (bool)$formulasService->evaluateCondition($formula, ['postalCode' => $postalCode], 'Postal code formula matching address');
62-
} catch (\Throwable $e) {
62+
} catch (\Throwable) {
6363
Craft::error('Error evaluating postal code formula: ' . $formula,'commerce');
6464
return false;
6565
}

src/elements/conditions/customers/CatalogPricingRuleCustomerCondition.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class CatalogPricingRuleCustomerCondition extends UserCondition
2424
*/
2525
protected function selectableConditionRules(): array
2626
{
27-
return array_filter(parent::selectableConditionRules(), static function($type) {
28-
return !in_array($type, [
29-
LastLoginDateConditionRule::class,
30-
SiteConditionRule::class,
31-
], true);
32-
});
27+
return array_filter(parent::selectableConditionRules(), static fn($type) => !in_array($type, [
28+
LastLoginDateConditionRule::class,
29+
SiteConditionRule::class,
30+
], true));
3331
}
3432
}

src/elements/conditions/orders/OrderStatusConditionRule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public function matchElement(ElementInterface $element): bool
7171

7272
protected function options(): array
7373
{
74-
return Plugin::getInstance()->getOrderStatuses()->getAllOrderStatuses()->mapWithKeys(function($status) {
75-
return [$status->uid => $status->name];
76-
})->all();
74+
return Plugin::getInstance()->getOrderStatuses()->getAllOrderStatuses()->mapWithKeys(fn($status) => [$status->uid => $status->name])->all();
7775
}
7876
}

src/elements/conditions/orders/PaymentGatewayConditionRule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function getExclusiveQueryParams(): array
4040
*/
4141
protected function options(): array
4242
{
43-
return Plugin::getInstance()->getGateways()->getAllGateways()->mapWithKeys(function($gateway) {
44-
return [$gateway->uid => $gateway->name];
45-
})->all();
43+
return Plugin::getInstance()->getGateways()->getAllGateways()->mapWithKeys(fn($gateway) => [$gateway->uid => $gateway->name])->all();
4644
}
4745

4846
/**

src/elements/conditions/orders/ShippingMethodConditionRule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function getExclusiveQueryParams(): array
4040
*/
4141
protected function options(): array
4242
{
43-
return Plugin::getInstance()->getShippingMethods()->getAllShippingMethods()->mapWithKeys(function($method) {
44-
return [$method->handle => $method->name];
45-
})->all();
43+
return Plugin::getInstance()->getShippingMethods()->getAllShippingMethods()->mapWithKeys(fn($method) => [$method->handle => $method->name])->all();
4644
}
4745

4846
/**

src/elements/conditions/purchasables/CatalogPricingRulePurchasableCondition.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class CatalogPricingRulePurchasableCondition extends ElementCondition
2424
*/
2525
protected function selectableConditionRules(): array
2626
{
27-
$types = array_filter(parent::selectableConditionRules(), static function($type) {
28-
return !in_array($type, [
29-
SiteConditionRule::class,
30-
], true);
31-
});
27+
$types = array_filter(parent::selectableConditionRules(), static fn($type) => !in_array($type, [
28+
SiteConditionRule::class,
29+
], true));
3230

3331
$types[] = PurchasableConditionRule::class;
3432
$types[] = SkuConditionRule::class;

src/elements/conditions/purchasables/PurchasableTypeConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function modifyQuery(ElementQueryInterface $query): void
4545
public function matchElement(ElementInterface $element): bool
4646
{
4747
/** @var Purchasable $element */
48-
return $this->matchValue(get_class($element));
48+
return $this->matchValue($element::class);
4949
}
5050

5151
/**

src/elements/db/PurchasableQuery.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,10 @@ abstract class PurchasableQuery extends ElementQuery
121121
*/
122122
public function __set($name, $value)
123123
{
124-
switch ($name) {
125-
case 'shippingCategory':
126-
$this->shippingCategory($value);
127-
break;
128-
default:
129-
parent::__set($name, $value);
130-
}
124+
match ($name) {
125+
'shippingCategory' => $this->shippingCategory($value),
126+
default => parent::__set($name, $value),
127+
};
131128
}
132129

133130
/**
@@ -195,7 +192,6 @@ public function availableForPurchase(?bool $value = true): static
195192
* ->one();
196193
* ```
197194
*
198-
* @param mixed $value
199195
* @return static self reference
200196
*/
201197
public function sku(mixed $value): static

0 commit comments

Comments
 (0)