Skip to content

Commit

Permalink
Laravel 6 remove helpers + style fixes (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
it-can authored and lukepolo committed Sep 6, 2019
1 parent 722ecee commit 1f297f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
21 changes: 11 additions & 10 deletions src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

namespace LukePOLO\LaraCart;

use Illuminate\Support\Arr;
use LukePOLO\LaraCart\Contracts\CouponContract;
use LukePOLO\LaraCart\Exceptions\ModelNotFound;
use LukePOLO\LaraCart\Traits\CartOptionsMagicMethodsTrait;

/**
* Class CartItem.
*
* @property int id
* @property int qty
* @property float tax
* @property float price
* @property int id
* @property int qty
* @property float tax
* @property float price
* @property string name
* @property array options
* @property bool taxable
* @property array options
* @property bool taxable
*/
class CartItem
{
Expand Down Expand Up @@ -44,8 +45,8 @@ class CartItem
/**
* CartItem constructor.
*
* @param $id
* @param $name
* @param $id
* @param $name
* @param int $qty
* @param string $price
* @param array $options
Expand Down Expand Up @@ -137,7 +138,7 @@ public function find($data)
*/
public function findSubItem($subItemHash)
{
return array_get($this->subItems, $subItemHash);
return Arr::get($this->subItems, $subItemHash);
}

/**
Expand Down Expand Up @@ -382,7 +383,7 @@ public function tax($amountNotTaxable = 0, $grossTax = true, $rounded = false, $
/**
* Sets the related model to the item.
*
* @param $itemModel
* @param $itemModel
* @param array $relations
*
* @throws ModelNotFound
Expand Down
3 changes: 2 additions & 1 deletion src/CartSubItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LukePOLO\LaraCart;

use Illuminate\Support\Arr;
use LukePOLO\LaraCart\Traits\CartOptionsMagicMethodsTrait;

/**
Expand Down Expand Up @@ -30,7 +31,7 @@ public function __construct($options)
$this->options['items'] = [];

foreach ($options as $option => $value) {
array_set($this->options, $option, $value);
Arr::set($this->options, $option, $value);
}

$this->itemHash = app(LaraCart::HASH)->hash($this->options);
Expand Down
35 changes: 18 additions & 17 deletions src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Arr;
use LukePOLO\LaraCart\Contracts\CouponContract;
use LukePOLO\LaraCart\Contracts\LaraCartContract;
use LukePOLO\LaraCart\Exceptions\ModelNotFound;
Expand Down Expand Up @@ -111,7 +112,7 @@ public function get($instance = 'default')
*/
public function getAttribute($attribute, $defaultValue = null)
{
return array_get($this->cart->attributes, $attribute, $defaultValue);
return Arr::get($this->cart->attributes, $attribute, $defaultValue);
}

/**
Expand All @@ -132,7 +133,7 @@ public function getAttributes()
*/
public function setAttribute($attribute, $value)
{
array_set($this->cart->attributes, $attribute, $value);
Arr::set($this->cart->attributes, $attribute, $value);

$this->update();
}
Expand Down Expand Up @@ -163,7 +164,7 @@ public function update()
*/
public function removeAttribute($attribute)
{
array_forget($this->cart->attributes, $attribute);
Arr::forget($this->cart->attributes, $attribute);

$this->update();
}
Expand All @@ -190,7 +191,7 @@ public function addLine($itemID, $name = null, $qty = 1, $price = '0.00', $optio
/**
* Creates a CartItem and then adds it to cart.
*
* @param $itemID
* @param $itemID
* @param null $name
* @param int $qty
* @param string $price
Expand Down Expand Up @@ -335,10 +336,10 @@ public function find($data)
switch (count($matches)) {
case 0:
return;
break;
break;
case 1:
return $matches[0];
break;
break;
default:
return $matches;
}
Expand All @@ -353,7 +354,7 @@ public function find($data)
*/
public function getItem($itemHash)
{
return array_get($this->getItems(), $itemHash);
return Arr::get($this->getItems(), $itemHash);
}

/**
Expand Down Expand Up @@ -465,7 +466,7 @@ public function getCoupons()
*/
public function findCoupon($code)
{
return array_get($this->cart->coupons, $code);
return Arr::get($this->cart->coupons, $code);
}

/**
Expand All @@ -492,7 +493,7 @@ public function addCoupon(CouponContract $coupon)
public function removeCoupon($code)
{
$this->removeCouponFromItems($code);
array_forget($this->cart->coupons, $code);
Arr::forget($this->cart->coupons, $code);
$this->update();
}

Expand All @@ -515,21 +516,21 @@ public function removeCoupons()
*/
public function getFee($name)
{
return array_get($this->cart->fees, $name, new CartFee(null, false));
return Arr::get($this->cart->fees, $name, new CartFee(null, false));
}

/**
* Allows to charge for additional fees that may or may not be taxable
* ex - service fee , delivery fee, tips.
*
* @param $name
* @param $amount
* @param $name
* @param $amount
* @param bool|false $taxable
* @param array $options
*/
public function addFee($name, $amount, $taxable = false, array $options = [])
{
array_set($this->cart->fees, $name, new CartFee($amount, $taxable, $options));
Arr::set($this->cart->fees, $name, new CartFee($amount, $taxable, $options));

$this->update();
}
Expand All @@ -541,7 +542,7 @@ public function addFee($name, $amount, $taxable = false, array $options = [])
*/
public function removeFee($name)
{
array_forget($this->cart->fees, $name);
Arr::forget($this->cart->fees, $name);

$this->update();
}
Expand Down Expand Up @@ -850,8 +851,8 @@ private function getItemModelOptions(Model $itemModel, $options = [])
* Gets a option from the model.
*
* @param Model $itemModel
* @param $attr
* @param null $defaultValue
* @param $attr
* @param null $defaultValue
*
* @return Model|null
*/
Expand All @@ -861,7 +862,7 @@ private function getFromModel(Model $itemModel, $attr, $defaultValue = null)

if (!empty($attr)) {
foreach (explode('.', $attr) as $attr) {
$variable = array_get($variable, $attr, $defaultValue);
$variable = Arr::get($variable, $attr, $defaultValue);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/LaraCartServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LukePOLO\LaraCart;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

/**
* Class LaraCartServiceProvider.
Expand Down Expand Up @@ -50,7 +51,7 @@ public function register()
$this->app->bind(
LaraCart::RANHASH,
function () {
return str_random(40);
return Str::random(40);
}
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Traits/CartOptionsMagicMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LukePOLO\LaraCart\Traits;

use Illuminate\Support\Arr;
use LukePOLO\LaraCart\CartItem;
use LukePOLO\LaraCart\Exceptions\InvalidPrice;
use LukePOLO\LaraCart\Exceptions\InvalidQuantity;
Expand All @@ -23,7 +24,7 @@ trait CartOptionsMagicMethodsTrait
*/
public function __get($option)
{
return array_get($this->options, $option);
return Arr::get($this->options, $option);
}

/**
Expand Down Expand Up @@ -61,8 +62,8 @@ public function __set($option, $value)
break;
}

$changed = (!empty(array_get($this->options, $option)) && array_get($this->options, $option) != $value);
array_set($this->options, $option, $value);
$changed = (!empty(Arr::get($this->options, $option)) && Arr::get($this->options, $option) != $value);
Arr::set($this->options, $option, $value);

if ($changed) {
if (is_callable([$this, 'generateHash'])) {
Expand Down

0 comments on commit 1f297f7

Please sign in to comment.