Skip to content

Commit

Permalink
Merge pull request #20 from offline-agency/analysis-VreOe6
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
SanaviaNicolas authored Dec 17, 2021
2 parents a8ca963 + fd95168 commit f046c2f
Showing 1 changed file with 54 additions and 59 deletions.
113 changes: 54 additions & 59 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Cart
/**
* Cart constructor.
*
* @param SessionManager $session
* @param Dispatcher $events
* @param SessionManager $session
* @param Dispatcher $events
*/
public function __construct(SessionManager $session, Dispatcher $events)
{
Expand All @@ -56,7 +56,7 @@ public function __construct(SessionManager $session, Dispatcher $events)
/**
* Set the current cart instance.
*
* @param string|null $instance
* @param string|null $instance
* @return Cart
*/
public function instance(string $instance = null): Cart
Expand All @@ -81,17 +81,17 @@ public function currentInstance(): string
/**
* Add an item to the cart.
*
* @param mixed $id
* @param mixed $name
* @param string|null $subtitle
* @param int|null $qty
* @param float|null $price
* @param float|null $totalPrice
* @param float|null $vat
* @param string|null $vatFcCode
* @param string|null $productFcCode
* @param string|null $urlImg
* @param array $options
* @param mixed $id
* @param mixed $name
* @param string|null $subtitle
* @param int|null $qty
* @param float|null $price
* @param float|null $totalPrice
* @param float|null $vat
* @param string|null $vatFcCode
* @param string|null $productFcCode
* @param string|null $urlImg
* @param array $options
* @return array|CartItem|CartItem[]
*/
public function add(
Expand All @@ -106,8 +106,7 @@ public function add(
string $productFcCode = '',
string $urlImg = '',
array $options = []
)
{
) {
if ($this->isMulti($id)) {
return array_map(function ($item) {
return $this->add($item);
Expand Down Expand Up @@ -146,8 +145,8 @@ public function add(
/**
* Update the cart item with the given rowId.
*
* @param string $rowId
* @param mixed $qty
* @param string $rowId
* @param mixed $qty
* @return CartItem|void
*/
public function update(string $rowId, $qty)
Expand Down Expand Up @@ -191,7 +190,7 @@ public function update(string $rowId, $qty)
/**
* Remove the cart item with the given rowId from the cart.
*
* @param string $rowId
* @param string $rowId
* @return void
*/
public function remove(string $rowId)
Expand All @@ -216,14 +215,14 @@ public function remove(string $rowId)
/**
* Get a cart item from the cart by its rowId.
*
* @param string $rowId
* @param string $rowId
* @return CartItem
*/
public function get(string $rowId)
{
$content = $this->getContent();

if (!$content->has($rowId)) {
if (! $content->has($rowId)) {
throw new InvalidRowIDException("The cart does not contain rowId {$rowId}.");
}

Expand Down Expand Up @@ -269,9 +268,9 @@ public function count()
/**
* Get the total price of the items in the cart.
*
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @return float
*/
public function total(int $decimals = null, string $decimalPoint = null, string $thousandSeparator = null): float
Expand All @@ -284,9 +283,9 @@ public function total(int $decimals = null, string $decimalPoint = null, string
/**
* Get the total vat of the items in the cart.
*
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @return float
*/
public function vat(int $decimals = null, string $decimalPoint = null, string $thousandSeparator = null): float
Expand All @@ -299,9 +298,9 @@ public function vat(int $decimals = null, string $decimalPoint = null, string $t
/**
* Get the subtotal (total - vat) of the items in the cart.
*
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeparator
* @return float
*/
public function subtotal(int $decimals = null, string $decimalPoint = null, string $thousandSeparator = null): float
Expand All @@ -314,7 +313,7 @@ public function subtotal(int $decimals = null, string $decimalPoint = null, stri
/**
* Search the cart content for a cart item matching the given search closure.
*
* @param Closure $search
* @param Closure $search
* @return Collection
*/
public function search(Closure $search): Collection
Expand All @@ -327,13 +326,13 @@ public function search(Closure $search): Collection
/**
* Associate the cart item with the given rowId with the given model.
*
* @param string $rowId
* @param mixed $model
* @param string $rowId
* @param mixed $model
* @return void
*/
public function associate(string $rowId, $model)
{
if (is_string($model) && !class_exists($model)) {
if (is_string($model) && ! class_exists($model)) {
throw new UnknownModelException("The supplied model {$model} does not exist.");
}

Expand All @@ -351,7 +350,7 @@ public function associate(string $rowId, $model)
/**
* Store the current instance of the cart.
*
* @param mixed $identifier
* @param mixed $identifier
* @return void
*/
public function store($identifier)
Expand All @@ -374,12 +373,12 @@ public function store($identifier)
/**
* Restore the cart with the given identifier.
*
* @param mixed $identifier
* @param mixed $identifier
* @return void
*/
public function restore($identifier)
{
if (!$this->storedCartWithIdentifierExists($identifier)) {
if (! $this->storedCartWithIdentifierExists($identifier)) {
return;
}

Expand Down Expand Up @@ -411,7 +410,7 @@ public function restore($identifier)
/**
* Magic method to make accessing the total, tax and subtotal properties possible.
*
* @param string $attribute
* @param string $attribute
* @return float|null
*/
public function __get(string $attribute)
Expand Down Expand Up @@ -465,7 +464,7 @@ protected function getContent(): Collection
* @param $productFcCode
* @param $vat
* @param $urlImg
* @param array $options
* @param array $options
* @return CartItem
*/
private function createCartItem(
Expand All @@ -480,8 +479,7 @@ private function createCartItem(
$vat,
$urlImg,
array $options
): CartItem
{
): CartItem {
if ($id instanceof Buyable) {
$cartItem = CartItem::fromBuyable($id);
$cartItem->setQuantity($name ?: 1);
Expand Down Expand Up @@ -512,12 +510,12 @@ private function createCartItem(
/**
* Check if the item is a multidimensional array or an array of Buyable.
*
* @param mixed $item
* @param mixed $item
* @return bool
*/
private function isMulti($item): bool
{
if (!is_array($item)) {
if (! is_array($item)) {
return false;
}

Expand Down Expand Up @@ -568,7 +566,7 @@ private function getConnectionName(): string
}

/**
* @param array $items
* @param array $items
* @return Collection
*/
public function addBatch(array $items): Collection
Expand Down Expand Up @@ -630,7 +628,7 @@ public function coupons(): array
Arr::set(
$coupons,
$coupon->couponCode,
(object)[
(object) [
'rowId' => $cartItem->rowId,
'couponCode' => $coupon->couponCode,
'couponType' => $coupon->couponType,
Expand All @@ -645,17 +643,16 @@ public function coupons(): array

/**
* @param $rowId
* @param string $couponCode
* @param string $couponType
* @param float $couponValue
* @param string $couponCode
* @param string $couponType
* @param float $couponValue
*/
public function applyCoupon(
$rowId,
string $couponCode,
string $couponType,
float $couponValue
)
{
) {
$cartItem = $this->get($rowId);

$cartItem->applyCoupon(
Expand All @@ -670,7 +667,7 @@ public function applyCoupon(

$this->session->put($this->instance, $content);

$this->coupons()[$couponCode] = (object)[
$this->coupons()[$couponCode] = (object) [
'rowId' => $rowId,
'couponCode' => $couponCode,
'couponType' => $couponType,
Expand All @@ -680,13 +677,12 @@ public function applyCoupon(

/**
* @param $rowId
* @param string $couponCode
* @param string $couponCode
*/
public function detachCoupon(
$rowId,
string $couponCode
)
{
) {
$cartItem = $this->get($rowId);

$cartItem->detachCoupon(
Expand All @@ -711,13 +707,12 @@ public function hasCoupons(): bool
}

/**
* @param string $couponCode
* @param string $couponCode
* @return array|\ArrayAccess|mixed|null
*/
public function getCoupon(
string $couponCode
)
{
) {
$coupons = $this->coupons();

return Arr::has($coupons, $couponCode)
Expand All @@ -726,11 +721,11 @@ public function getCoupon(
}

/**
* @param string|null $couponCode
* @param string|null $couponCode
*/
public function removeCoupon(?string $couponCode)
{
if (!is_null($couponCode)) {
if (! is_null($couponCode)) {
unset($this->coupons()[$couponCode]);
}
}
Expand Down

0 comments on commit f046c2f

Please sign in to comment.