Update Cart.php

This commit is contained in:
Patrick
2022-01-18 01:21:59 +01:00
committed by GitHub
parent c7e3774f9f
commit ca22d5d2f5

View File

@@ -86,7 +86,7 @@ class Cart
*
* @return \Gloudemans\Shoppingcart\Cart
*/
public function instance($instance = null)
public function instance($instance = null): self
{
$instance = $instance ?: self::DEFAULT_INSTANCE;
@@ -105,7 +105,7 @@ class Cart
*
* @return string
*/
public function currentInstance()
public function currentInstance(): string
{
return str_replace('cart.', '', $this->instance);
}
@@ -122,7 +122,7 @@ class Cart
*
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function add($id, ?string $name = null, $qty = null, ?Money $price = null, $weight = 0, array $options = [])
public function add($id, ?string $name = null, $qty = null, ?Money $price = null, $weight = 0, array $options = []): CartItem
{
if ($this->isMulti($id)) {
return array_map(function ($item) {
@@ -145,7 +145,7 @@ class Cart
*
* @return \Gloudemans\Shoppingcart\CartItem The CartItem
*/
public function addCartItem(CartItem $item, bool $keepDiscount = false, bool $keepTax = false, bool $dispatchEvent = true)
public function addCartItem(CartItem $item, bool $keepDiscount = false, bool $keepTax = false, bool $dispatchEvent = true): CartItem
{
if (!$keepDiscount) {
$item->setDiscountRate($this->discount);
@@ -184,7 +184,7 @@ class Cart
*
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function update(string $rowId, $qty)
public function update(string $rowId, $qty): ?CartItem
{
$cartItem = $this->get($rowId);
@@ -212,7 +212,7 @@ class Cart
if ($cartItem->qty <= 0) {
$this->remove($cartItem->rowId);
return;
return null;
} else {
if (isset($itemOldIndex)) {
$content = $content->slice(0, $itemOldIndex)
@@ -239,7 +239,7 @@ class Cart
*
* @return void
*/
public function remove(string $rowId)
public function remove(string $rowId): void
{
$cartItem = $this->get($rowId);
@@ -261,7 +261,7 @@ class Cart
*
* @return \Gloudemans\Shoppingcart\CartItem
*/
public function get(string $rowId)
public function get(string $rowId): CartItem
{
$content = $this->getContent();
@@ -277,7 +277,7 @@ class Cart
*
* @return void
*/
public function destroy()
public function destroy(): void
{
$this->session->remove($this->instance);
}
@@ -287,7 +287,7 @@ class Cart
*
* @return \Illuminate\Support\Collection
*/
public function content()
public function content(): Collection
{
if (is_null($this->session->get($this->instance))) {
return new Collection([]);
@@ -298,10 +298,8 @@ class Cart
/**
* Get the total quantity of all CartItems in the cart.
*
* @return int|float
*/
public function count()
public function count(): int
{
return $this->getContent()->sum('qty');
}
@@ -475,7 +473,7 @@ class Cart
*
* @return void
*/
public function associate(string $rowId, $model)
public function associate(string $rowId, $model): void
{
if (is_string($model) && !class_exists($model)) {
throw new UnknownModelException("The supplied model {$model} does not exist.");
@@ -500,7 +498,7 @@ class Cart
*
* @return void
*/
public function setTax(string $rowId, $taxRate)
public function setTax(string $rowId, $taxRate): void
{
$cartItem = $this->get($rowId);
@@ -519,7 +517,7 @@ class Cart
*
* @param float $discount
*/
public function setGlobalTax($taxRate)
public function setGlobalTax($taxRate): void
{
$this->taxRate = $taxRate;
@@ -539,7 +537,7 @@ class Cart
*
* @return void
*/
public function setDiscount(string $rowId, $discount)
public function setDiscount(string $rowId, $discount): void
{
$cartItem = $this->get($rowId);
@@ -560,7 +558,7 @@ class Cart
*
* @return void
*/
public function setGlobalDiscount($discount)
public function setGlobalDiscount($discount): void
{
$this->discount = $discount;
@@ -579,7 +577,7 @@ class Cart
*
* @return void
*/
public function store($identifier)
public function store($identifier): void
{
$content = $this->getContent();
@@ -611,7 +609,7 @@ class Cart
*
* @return void
*/
public function restore($identifier)
public function restore($identifier): void
{
if ($identifier instanceof InstanceIdentifier) {
$identifier = $identifier->getInstanceIdentifier();
@@ -655,7 +653,7 @@ class Cart
*
* @return void
*/
public function erase($identifier)
public function erase($identifier): void
{
if ($identifier instanceof InstanceIdentifier) {
$identifier = $identifier->getInstanceIdentifier();
@@ -682,7 +680,7 @@ class Cart
*
* @return bool
*/
public function merge($identifier, bool $keepDiscount = false, bool $keepTax = false, bool $dispatchAdd = true, $instance = self::DEFAULT_INSTANCE)
public function merge($identifier, bool $keepDiscount = false, bool $keepTax = false, bool $dispatchAdd = true, $instance = self::DEFAULT_INSTANCE): bool
{
if (!$this->storedCartInstanceWithIdentifierExists($instance, $identifier)) {
return false;
@@ -706,10 +704,8 @@ class Cart
* Magic method to make accessing the total, tax and subtotal properties possible.
*
* @param string $attribute
*
* @return float|null
*/
public function __get(string $attribute)
public function __get(string $attribute): ?Money
{
switch ($attribute) {
case 'total':
@@ -719,7 +715,7 @@ class Cart
case 'subtotal':
return $this->subtotal();
default:
return;
return null;
}
}