Skip to content

Commit

Permalink
Improve docblocks, fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBelgium committed Feb 2, 2019
1 parent 968fabf commit cf8bf68
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
59 changes: 30 additions & 29 deletions src/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Gloudemans\Shoppingcart;

use Closure;
use Illuminate\Database\Connection;
use Illuminate\Support\Collection;
use Illuminate\Session\SessionManager;
use Illuminate\Database\DatabaseManager;
Expand All @@ -22,14 +23,14 @@ class Cart
/**
* Instance of the session manager.
*
* @var \Illuminate\Session\SessionManager
* @var SessionManager
*/
private $session;

/**
* Instance of the event dispatcher.
*
* @var \Illuminate\Contracts\Events\Dispatcher
* @var Dispatcher
*/
private $events;

Expand All @@ -50,8 +51,8 @@ class Cart
/**
* Cart constructor.
*
* @param \Illuminate\Session\SessionManager $session
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @param SessionManager $session
* @param Dispatcher $events
*/
public function __construct(SessionManager $session, Dispatcher $events)
{
Expand All @@ -66,7 +67,7 @@ public function __construct(SessionManager $session, Dispatcher $events)
* Set the current cart instance.
*
* @param string|null $instance
* @return \Gloudemans\Shoppingcart\Cart
* @return Cart
*/
public function instance($instance = null)
{
Expand Down Expand Up @@ -95,7 +96,7 @@ public function currentInstance()
* @param int|float $qty
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
{
Expand Down Expand Up @@ -125,8 +126,8 @@ public function add($id, $name = null, $qty = null, $price = null, array $option
/**
* Sets/adds an additional cost on the cart.
*
* @param $type
* @param $price
* @param string $name
* @param float $price
* @todo add in session
*/
public function addCost($name, $price)
Expand All @@ -142,22 +143,22 @@ public function addCost($name, $price)
* @param $name
* @param int|null $decimals
* @param string|null $decimalPoint
* @param string|null $thousandSeperator
* @param string|null $thousandSeparator
* @return string
*/
public function getCost($name, $decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function getCost($name, $decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
$cost = $this->extraCosts->get($name, 0);

return $this->numberFormat($cost, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($cost, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Update the cart item with the given rowId.
*
* @param string $rowId
* @param mixed $qty
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public function update($rowId, $qty)
{
Expand Down Expand Up @@ -219,7 +220,7 @@ public function remove($rowId)
* Get a cart item from the cart by its rowId.
*
* @param string $rowId
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public function get($rowId)
{
Expand Down Expand Up @@ -272,10 +273,10 @@ public function count()
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function total($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
$content = $this->getContent();

Expand All @@ -289,45 +290,45 @@ public function total($decimals = null, $decimalPoint = null, $thousandSeperator

$total += $totalCost;

return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Get the total tax of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return float
*/
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function tax($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
$content = $this->getContent();

$tax = $content->reduce(function ($tax, CartItem $cartItem) {
return $tax + ($cartItem->qty * $cartItem->tax);
}, 0);

return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Get the subtotal (total - tax) of the items in the cart.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return float
*/
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
$content = $this->getContent();

$subTotal = $content->reduce(function ($subTotal, CartItem $cartItem) {
return $subTotal + ($cartItem->qty * $cartItem->price);
}, 0);

return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($subTotal, $decimals, $decimalPoint, $thousandSeparator);
}

/**
Expand Down Expand Up @@ -492,7 +493,7 @@ protected function getContent()
* @param int|float $qty
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
private function createCartItem($id, $name, $qty, $price, array $options)
{
Expand Down Expand Up @@ -538,7 +539,7 @@ private function storedCartWithIdentifierExists($identifier)
/**
* Get the database connection.
*
* @return \Illuminate\Database\Connection
* @return Connection
*/
private function getConnection()
{
Expand Down Expand Up @@ -575,21 +576,21 @@ private function getConnectionName()
* @param $value
* @param $decimals
* @param $decimalPoint
* @param $thousandSeperator
* @param $thousandSeparator
* @return string
*/
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator)
private function numberFormat($value, $decimals, $decimalPoint, $thousandSeparator)
{
if(is_null($decimals)){
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
}
if(is_null($decimalPoint)){
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}
if(is_null($thousandSeperator)){
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
if(is_null($thousandSeparator)){
$thousandSeparator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}

return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
return number_format($value, $decimals, $decimalPoint, $thousandSeparator);
}
}
62 changes: 31 additions & 31 deletions src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ public function __construct($id, $name, $price, array $options = [])
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function price($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function price($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Returns the formatted price with TAX.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function priceTax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function priceTax($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->priceTax, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->priceTax, $decimals, $decimalPoint, $thousandSeparator);
}

/**
Expand All @@ -123,12 +123,12 @@ public function priceTax($decimals = null, $decimalPoint = null, $thousandSepera
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function subtotal($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeparator);
}

/**
Expand All @@ -137,38 +137,38 @@ public function subtotal($decimals = null, $decimalPoint = null, $thousandSepera
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function total($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function total($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->total, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->total, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Returns the formatted tax.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function tax($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeparator);
}

/**
* Returns the formatted tax.
*
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
public function taxTotal($decimals = null, $decimalPoint = null, $thousandSeperator = null)
public function taxTotal($decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
return $this->numberFormat($this->taxTotal, $decimals, $decimalPoint, $thousandSeperator);
return $this->numberFormat($this->taxTotal, $decimals, $decimalPoint, $thousandSeparator);
}

/**
Expand All @@ -187,7 +187,7 @@ public function setQuantity($qty)
/**
* Update the cart item from a Buyable.
*
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
* @param Buyable $item
* @return void
*/
public function updateFromBuyable(Buyable $item)
Expand Down Expand Up @@ -220,7 +220,7 @@ public function updateFromArray(array $attributes)
* Associate the cart item with the given model.
*
* @param mixed $model
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public function associate($model)
{
Expand All @@ -233,7 +233,7 @@ public function associate($model)
* Set the tax rate.
*
* @param int|float $taxRate
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public function setTaxRate($taxRate)
{
Expand Down Expand Up @@ -284,9 +284,9 @@ public function __get($attribute)
/**
* Create a new instance from a Buyable.
*
* @param \Gloudemans\Shoppingcart\Contracts\Buyable $item
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
* @param Buyable $item
* @param array $options
* @return CartItem
*/
public static function fromBuyable(Buyable $item, array $options = [])
{
Expand All @@ -297,7 +297,7 @@ public static function fromBuyable(Buyable $item, array $options = [])
* Create a new instance from the given array.
*
* @param array $attributes
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public static function fromArray(array $attributes)
{
Expand All @@ -313,7 +313,7 @@ public static function fromArray(array $attributes)
* @param string $name
* @param float $price
* @param array $options
* @return \Gloudemans\Shoppingcart\CartItem
* @return CartItem
*/
public static function fromAttributes($id, $name, $price, array $options = [])
{
Expand Down Expand Up @@ -370,10 +370,10 @@ public function toJson($options = 0)
* @param float $value
* @param int $decimals
* @param string $decimalPoint
* @param string $thousandSeperator
* @param string $thousandSeparator
* @return string
*/
private function numberFormat($value, $decimals = null, $decimalPoint = null, $thousandSeperator = null)
private function numberFormat($value, $decimals = null, $decimalPoint = null, $thousandSeparator = null)
{
if (is_null($decimals)){
$decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals');
Expand All @@ -383,10 +383,10 @@ private function numberFormat($value, $decimals = null, $decimalPoint = null, $t
$decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point');
}

if (is_null($thousandSeperator)){
$thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
if (is_null($thousandSeparator)){
$thousandSeparator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator');
}

return number_format($value, $decimals, $decimalPoint, $thousandSeperator);
return number_format($value, $decimals, $decimalPoint, $thousandSeparator);
}
}

0 comments on commit cf8bf68

Please sign in to comment.