Skip to content

Commit e9eb878

Browse files
Copilotwilr
andauthored
Fix code review issues: null checks in ProductCurrencyPrice, fix PHPDoc type
Agent-Logs-Url: https://github.com/silvershop/silvershop-core/sessions/9ea8f7d5-bfca-4c21-a17f-f048b08ff414 Co-authored-by: wilr <101629+wilr@users.noreply.github.com>
1 parent 4b43929 commit e9eb878

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/Model/Product/ProductCurrencyPrice.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,25 @@ class ProductCurrencyPrice extends DataObject
5050

5151
public function canCreate($member = null, $context = []): bool
5252
{
53-
return $this->Product()->canEdit($member);
53+
$product = $this->Product();
54+
return $product && $product->exists() ? $product->canEdit($member) : false;
5455
}
5556

5657
public function canEdit($member = null): bool
5758
{
58-
return $this->Product()->canEdit($member);
59+
$product = $this->Product();
60+
return $product && $product->exists() ? $product->canEdit($member) : false;
5961
}
6062

6163
public function canDelete($member = null): bool
6264
{
63-
return $this->Product()->canEdit($member);
65+
$product = $this->Product();
66+
return $product && $product->exists() ? $product->canEdit($member) : false;
6467
}
6568

6669
public function canView($member = null): bool
6770
{
68-
return $this->Product()->canView($member);
71+
$product = $this->Product();
72+
return $product && $product->exists() ? $product->canView($member) : false;
6973
}
7074
}

tests/php/Currency/ProductCurrencyPriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class ProductCurrencyPriceTest extends SapphireTest
2222
protected static $fixture_file = __DIR__ . '/../Fixtures/shop.yml';
2323

2424
/**
25-
* @var SimpleCurrencyService
25+
* @var CurrencyService
2626
*/
2727
private CurrencyService $currencyService;
2828

0 commit comments

Comments
 (0)