diff --git a/src/CartItem.php b/src/CartItem.php index c68abd6..57cc569 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -2,6 +2,7 @@ namespace LukePOLO\LaraCart; +use Illuminate\Support\Arr; use LukePOLO\LaraCart\Contracts\CouponContract; use LukePOLO\LaraCart\Exceptions\ModelNotFound; use LukePOLO\LaraCart\Traits\CartOptionsMagicMethodsTrait; @@ -9,13 +10,13 @@ /** * 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 { @@ -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 @@ -137,7 +138,7 @@ public function find($data) */ public function findSubItem($subItemHash) { - return array_get($this->subItems, $subItemHash); + return Arr::get($this->subItems, $subItemHash); } /** @@ -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 diff --git a/src/CartSubItem.php b/src/CartSubItem.php index 8ab2090..450b7c8 100644 --- a/src/CartSubItem.php +++ b/src/CartSubItem.php @@ -2,6 +2,7 @@ namespace LukePOLO\LaraCart; +use Illuminate\Support\Arr; use LukePOLO\LaraCart\Traits\CartOptionsMagicMethodsTrait; /** @@ -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); diff --git a/src/LaraCart.php b/src/LaraCart.php index 8931d6f..3f34c21 100644 --- a/src/LaraCart.php +++ b/src/LaraCart.php @@ -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; @@ -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); } /** @@ -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(); } @@ -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(); } @@ -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 @@ -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; } @@ -353,7 +354,7 @@ public function find($data) */ public function getItem($itemHash) { - return array_get($this->getItems(), $itemHash); + return Arr::get($this->getItems(), $itemHash); } /** @@ -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); } /** @@ -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(); } @@ -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(); } @@ -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(); } @@ -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 */ @@ -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); } } diff --git a/src/LaraCartServiceProvider.php b/src/LaraCartServiceProvider.php index 88e994d..528d314 100644 --- a/src/LaraCartServiceProvider.php +++ b/src/LaraCartServiceProvider.php @@ -3,6 +3,7 @@ namespace LukePOLO\LaraCart; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; /** * Class LaraCartServiceProvider. @@ -50,7 +51,7 @@ public function register() $this->app->bind( LaraCart::RANHASH, function () { - return str_random(40); + return Str::random(40); } ); } diff --git a/src/Traits/CartOptionsMagicMethodsTrait.php b/src/Traits/CartOptionsMagicMethodsTrait.php index c3967cb..3832cd4 100644 --- a/src/Traits/CartOptionsMagicMethodsTrait.php +++ b/src/Traits/CartOptionsMagicMethodsTrait.php @@ -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; @@ -23,7 +24,7 @@ trait CartOptionsMagicMethodsTrait */ public function __get($option) { - return array_get($this->options, $option); + return Arr::get($this->options, $option); } /** @@ -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'])) {