diff --git a/.gitignore b/.gitignore index 2c1fc0c1..225319b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.phar composer.lock -.DS_Store \ No newline at end of file +.DS_Store +.idea/ \ No newline at end of file diff --git a/.php_cs.cache b/.php_cs.cache new file mode 100644 index 00000000..91ee0e38 --- /dev/null +++ b/.php_cs.cache @@ -0,0 +1 @@ +{"php":"7.3.3","version":"2.14.2","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/CartItemOptions.php":3665257661,"src\/CanBeBought.php":1005429606,"src\/Cart.php":3875270740,"src\/CartItem.php":3911352031,"src\/Contracts\/Buyable.php":1677486857,"src\/Exceptions\/InvalidRowIDException.php":2549804056,"src\/Exceptions\/CartAlreadyStoredException.php":3751240650,"src\/Exceptions\/UnknownModelException.php":3696588695,"src\/Facades\/Cart.php":3887252644,"src\/ShoppingcartServiceProvider.php":2316062521}} \ No newline at end of file diff --git a/composer.json b/composer.json index 41f7b92a..77f93873 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ } ], "require": { - "illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*", - "illuminate/session": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*", - "illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*" + "illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*", + "illuminate/session": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*", + "illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.* || 5.8.*" }, "require-dev": { "phpunit/phpunit": "~5.0 || ~6.0 || ~7.0", diff --git a/src/CanBeBought.php b/src/CanBeBought.php index 96e0e534..49d4c312 100644 --- a/src/CanBeBought.php +++ b/src/CanBeBought.php @@ -22,9 +22,15 @@ public function getBuyableIdentifier($options = null) */ public function getBuyableDescription($options = null) { - if(property_exists($this, 'name')) return $this->name; - if(property_exists($this, 'title')) return $this->title; - if(property_exists($this, 'description')) return $this->description; + if (property_exists($this, 'name')) { + return $this->name; + } + if (property_exists($this, 'title')) { + return $this->title; + } + if (property_exists($this, 'description')) { + return $this->description; + } return null; } @@ -36,8 +42,10 @@ public function getBuyableDescription($options = null) */ public function getBuyablePrice($options = null) { - if(property_exists($this, 'price')) return $this->price; + if (property_exists($this, 'price')) { + return $this->price; + } return null; } -} \ No newline at end of file +} diff --git a/src/Cart.php b/src/Cart.php index 09853dba..7e9d846b 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -25,7 +25,7 @@ class Cart /** * Instance of the event dispatcher. - * + * * @var \Illuminate\Contracts\Events\Dispatcher */ private $events; @@ -40,7 +40,7 @@ class Cart /** * Cart constructor. * - * @param \Illuminate\Session\SessionManager $session + * @param \Illuminate\Session\SessionManager $session * @param \Illuminate\Contracts\Events\Dispatcher $events */ public function __construct(SessionManager $session, Dispatcher $events) @@ -79,11 +79,11 @@ public function currentInstance() /** * Add an item to the cart. * - * @param mixed $id - * @param mixed $name + * @param mixed $id + * @param mixed $name * @param int|float $qty - * @param float $price - * @param array $options + * @param float $price + * @param array $options * @return \Gloudemans\Shoppingcart\CartItem */ public function add($id, $name = null, $qty = null, $price = null, array $options = []) @@ -103,8 +103,8 @@ public function add($id, $name = null, $qty = null, $price = null, array $option } $content->put($cartItem->rowId, $cartItem); - - $this->events->fire('cart.added', $cartItem); + + $this->events->dispatch('cart.added', $cartItem); $this->session->put($this->instance, $content); @@ -115,7 +115,7 @@ public function add($id, $name = null, $qty = null, $price = null, array $option * Update the cart item with the given rowId. * * @param string $rowId - * @param mixed $qty + * @param mixed $qty * @return \Gloudemans\Shoppingcart\CartItem */ public function update($rowId, $qty) @@ -148,7 +148,7 @@ public function update($rowId, $qty) $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.updated', $cartItem); + $this->events->dispatch('cart.updated', $cartItem); $this->session->put($this->instance, $content); @@ -169,7 +169,7 @@ public function remove($rowId) $content->pull($cartItem->rowId); - $this->events->fire('cart.removed', $cartItem); + $this->events->dispatch('cart.removed', $cartItem); $this->session->put($this->instance, $content); } @@ -184,8 +184,9 @@ public function get($rowId) { $content = $this->getContent(); - if ( ! $content->has($rowId)) + if (!$content->has($rowId)) { throw new InvalidRowIDException("The cart does not contain rowId {$rowId}."); + } return $content->get($rowId); } @@ -229,7 +230,7 @@ public function count() /** * Get the total price of the items in the cart. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -248,7 +249,7 @@ public function total($decimals = null, $decimalPoint = null, $thousandSeperator /** * Get the total tax of the items in the cart. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return float @@ -267,7 +268,7 @@ public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = /** * Get the subtotal (total - tax) of the items in the cart. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return float @@ -300,12 +301,12 @@ public function search(Closure $search) * Associate the cart item with the given rowId with the given model. * * @param string $rowId - * @param mixed $model + * @param mixed $model * @return void */ public function associate($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."); } @@ -323,7 +324,7 @@ public function associate($rowId, $model) /** * Set the tax rate for the cart item with the given rowId. * - * @param string $rowId + * @param string $rowId * @param int|float $taxRate * @return void */ @@ -360,7 +361,7 @@ public function store($identifier) 'content' => serialize($content) ]); - $this->events->fire('cart.stored'); + $this->events->dispatch('cart.stored'); } /** @@ -371,7 +372,7 @@ public function store($identifier) */ public function restore($identifier) { - if( ! $this->storedCartWithIdentifierExists($identifier)) { + if (!$this->storedCartWithIdentifierExists($identifier)) { return; } @@ -390,7 +391,7 @@ public function restore($identifier) $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.restored'); + $this->events->dispatch('cart.restored'); $this->session->put($this->instance, $content); @@ -408,15 +409,15 @@ public function restore($identifier) */ public function __get($attribute) { - if($attribute === 'total') { + if ($attribute === 'total') { return $this->total(); } - if($attribute === 'tax') { + if ($attribute === 'tax') { return $this->tax(); } - if($attribute === 'subtotal') { + if ($attribute === 'subtotal') { return $this->subtotal(); } @@ -440,11 +441,11 @@ protected function getContent() /** * Create a new CartItem from the supplied attributes. * - * @param mixed $id - * @param mixed $name + * @param mixed $id + * @param mixed $name * @param int|float $qty - * @param float $price - * @param array $options + * @param float $price + * @param array $options * @return \Gloudemans\Shoppingcart\CartItem */ private function createCartItem($id, $name, $qty, $price, array $options) @@ -474,7 +475,9 @@ private function createCartItem($id, $name, $qty, $price, array $options) */ private function isMulti($item) { - if ( ! is_array($item)) return false; + if (!is_array($item)) { + return false; + } return is_array(head($item)) || head($item) instanceof Buyable; } @@ -533,13 +536,13 @@ private function getConnectionName() */ private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator) { - if(is_null($decimals)){ + if (is_null($decimals)) { $decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals'); } - if(is_null($decimalPoint)){ + if (is_null($decimalPoint)) { $decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point'); } - if(is_null($thousandSeperator)){ + if (is_null($thousandSeperator)) { $thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator'); } diff --git a/src/CartItem.php b/src/CartItem.php index 64e2cf68..d7a9885a 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -68,33 +68,33 @@ class CartItem implements Arrayable, Jsonable * CartItem constructor. * * @param int|string $id - * @param string $name - * @param float $price - * @param array $options + * @param string $name + * @param float $price + * @param array $options */ public function __construct($id, $name, $price, array $options = []) { - if(empty($id)) { + if (empty($id)) { throw new \InvalidArgumentException('Please supply a valid identifier.'); } - if(empty($name)) { + if (empty($name)) { throw new \InvalidArgumentException('Please supply a valid name.'); } - if(strlen($price) < 0 || ! is_numeric($price)) { + if (strlen($price) < 0 || !is_numeric($price)) { throw new \InvalidArgumentException('Please supply a valid price.'); } - $this->id = $id; - $this->name = $name; - $this->price = floatval($price); - $this->options = new CartItemOptions($options); + $this->id = $id; + $this->name = $name; + $this->price = floatval($price); + $this->options = new CartItemOptions($options); $this->rowId = $this->generateRowId($id, $options); } /** * Returns the formatted price without TAX. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -103,11 +103,11 @@ public function price($decimals = null, $decimalPoint = null, $thousandSeperator { return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted price with TAX. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -121,7 +121,7 @@ public function priceTax($decimals = null, $decimalPoint = null, $thousandSepera * Returns the formatted subtotal. * Subtotal is price for whole CartItem without TAX * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -130,12 +130,12 @@ public function subtotal($decimals = null, $decimalPoint = null, $thousandSepera { return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted total. * Total is price for whole CartItem with TAX * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -148,7 +148,7 @@ public function total($decimals = null, $decimalPoint = null, $thousandSeperator /** * Returns the formatted tax. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -157,11 +157,11 @@ public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = { return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted tax. * - * @param int $decimals + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string @@ -178,8 +178,9 @@ public function taxTotal($decimals = null, $decimalPoint = null, $thousandSepera */ public function setQuantity($qty) { - if(empty($qty) || ! is_numeric($qty)) + if (empty($qty) || !is_numeric($qty)) { throw new \InvalidArgumentException('Please supply a valid quantity.'); + } $this->qty = $qty; } @@ -192,9 +193,9 @@ public function setQuantity($qty) */ public function updateFromBuyable(Buyable $item) { - $this->id = $item->getBuyableIdentifier($this->options); - $this->name = $item->getBuyableDescription($this->options); - $this->price = $item->getBuyablePrice($this->options); + $this->id = $item->getBuyableIdentifier($this->options); + $this->name = $item->getBuyableDescription($this->options); + $this->price = $item->getBuyablePrice($this->options); $this->priceTax = $this->price + $this->tax; } @@ -206,12 +207,12 @@ public function updateFromBuyable(Buyable $item) */ public function updateFromArray(array $attributes) { - $this->id = array_get($attributes, 'id', $this->id); - $this->qty = array_get($attributes, 'qty', $this->qty); - $this->name = array_get($attributes, 'name', $this->name); - $this->price = array_get($attributes, 'price', $this->price); + $this->id = array_get($attributes, 'id', $this->id); + $this->qty = array_get($attributes, 'qty', $this->qty); + $this->name = array_get($attributes, 'name', $this->name); + $this->price = array_get($attributes, 'price', $this->price); $this->priceTax = $this->price + $this->tax; - $this->options = new CartItemOptions(array_get($attributes, 'options', $this->options)); + $this->options = new CartItemOptions(array_get($attributes, 'options', $this->options)); $this->rowId = $this->generateRowId($this->id, $this->options->all()); } @@ -225,7 +226,7 @@ public function updateFromArray(array $attributes) public function associate($model) { $this->associatedModel = is_string($model) ? $model : get_class($model); - + return $this; } @@ -238,7 +239,7 @@ public function associate($model) public function setTaxRate($taxRate) { $this->taxRate = $taxRate; - + return $this; } @@ -250,31 +251,31 @@ public function setTaxRate($taxRate) */ public function __get($attribute) { - if(property_exists($this, $attribute)) { + if (property_exists($this, $attribute)) { return $this->{$attribute}; } - if($attribute === 'priceTax') { + if ($attribute === 'priceTax') { return $this->price + $this->tax; } - - if($attribute === 'subtotal') { + + if ($attribute === 'subtotal') { return $this->qty * $this->price; } - - if($attribute === 'total') { + + if ($attribute === 'total') { return $this->qty * ($this->priceTax); } - if($attribute === 'tax') { + if ($attribute === 'tax') { return $this->price * ($this->taxRate / 100); } - - if($attribute === 'taxTotal') { + + if ($attribute === 'taxTotal') { return $this->tax * $this->qty; } - if($attribute === 'model' && isset($this->associatedModel)) { + if ($attribute === 'model' && isset($this->associatedModel)) { return with(new $this->associatedModel)->find($this->id); } @@ -285,7 +286,7 @@ public function __get($attribute) * Create a new instance from a Buyable. * * @param \Gloudemans\Shoppingcart\Contracts\Buyable $item - * @param array $options + * @param array $options * @return \Gloudemans\Shoppingcart\CartItem */ public static function fromBuyable(Buyable $item, array $options = []) @@ -310,9 +311,9 @@ public static function fromArray(array $attributes) * Create a new instance from the given attributes. * * @param int|string $id - * @param string $name - * @param float $price - * @param array $options + * @param string $name + * @param float $price + * @param array $options * @return \Gloudemans\Shoppingcart\CartItem */ public static function fromAttributes($id, $name, $price, array $options = []) @@ -324,7 +325,7 @@ public static function fromAttributes($id, $name, $price, array $options = []) * Generate a unique id for the cart item. * * @param string $id - * @param array $options + * @param array $options * @return string */ protected function generateRowId($id, array $options) @@ -342,13 +343,13 @@ protected function generateRowId($id, array $options) public function toArray() { return [ - 'rowId' => $this->rowId, - 'id' => $this->id, - 'name' => $this->name, - 'qty' => $this->qty, - 'price' => $this->price, - 'options' => $this->options->toArray(), - 'tax' => $this->tax, + 'rowId' => $this->rowId, + 'id' => $this->id, + 'name' => $this->name, + 'qty' => $this->qty, + 'price' => $this->price, + 'options' => $this->options->toArray(), + 'tax' => $this->tax, 'subtotal' => $this->subtotal ]; } @@ -367,23 +368,23 @@ public function toJson($options = 0) /** * Get the formatted number. * - * @param float $value - * @param int $decimals + * @param float $value + * @param int $decimals * @param string $decimalPoint * @param string $thousandSeperator * @return string */ private function numberFormat($value, $decimals, $decimalPoint, $thousandSeperator) { - if (is_null($decimals)){ + if (is_null($decimals)) { $decimals = is_null(config('cart.format.decimals')) ? 2 : config('cart.format.decimals'); } - if (is_null($decimalPoint)){ + if (is_null($decimalPoint)) { $decimalPoint = is_null(config('cart.format.decimal_point')) ? '.' : config('cart.format.decimal_point'); } - if (is_null($thousandSeperator)){ + if (is_null($thousandSeperator)) { $thousandSeperator = is_null(config('cart.format.thousand_seperator')) ? ',' : config('cart.format.thousand_seperator'); } diff --git a/src/CartItemOptions.php b/src/CartItemOptions.php index bbd24e9c..1b802053 100644 --- a/src/CartItemOptions.php +++ b/src/CartItemOptions.php @@ -16,4 +16,4 @@ public function __get($key) { return $this->get($key); } -} \ No newline at end of file +} diff --git a/src/Contracts/Buyable.php b/src/Contracts/Buyable.php index f5bfeb7b..a7edd821 100644 --- a/src/Contracts/Buyable.php +++ b/src/Contracts/Buyable.php @@ -24,4 +24,4 @@ public function getBuyableDescription($options = null); * @return float */ public function getBuyablePrice($options = null); -} \ No newline at end of file +} diff --git a/src/Exceptions/CartAlreadyStoredException.php b/src/Exceptions/CartAlreadyStoredException.php index cd122592..a3ddcce1 100644 --- a/src/Exceptions/CartAlreadyStoredException.php +++ b/src/Exceptions/CartAlreadyStoredException.php @@ -4,4 +4,6 @@ use RuntimeException; -class CartAlreadyStoredException extends RuntimeException {} \ No newline at end of file +class CartAlreadyStoredException extends RuntimeException +{ +} diff --git a/src/Exceptions/InvalidRowIDException.php b/src/Exceptions/InvalidRowIDException.php index c475049a..df42cb97 100644 --- a/src/Exceptions/InvalidRowIDException.php +++ b/src/Exceptions/InvalidRowIDException.php @@ -4,4 +4,6 @@ use RuntimeException; -class InvalidRowIDException extends RuntimeException {} \ No newline at end of file +class InvalidRowIDException extends RuntimeException +{ +} diff --git a/src/Exceptions/UnknownModelException.php b/src/Exceptions/UnknownModelException.php index c98a3fdc..c9a8a274 100644 --- a/src/Exceptions/UnknownModelException.php +++ b/src/Exceptions/UnknownModelException.php @@ -4,4 +4,6 @@ use RuntimeException; -class UnknownModelException extends RuntimeException {} \ No newline at end of file +class UnknownModelException extends RuntimeException +{ +} diff --git a/src/Facades/Cart.php b/src/Facades/Cart.php index e75e0b8c..b6dfda17 100644 --- a/src/Facades/Cart.php +++ b/src/Facades/Cart.php @@ -3,7 +3,8 @@ use Illuminate\Support\Facades\Facade; -class Cart extends Facade { +class Cart extends Facade +{ /** * Get the registered name of the component. * diff --git a/src/ShoppingcartServiceProvider.php b/src/ShoppingcartServiceProvider.php index 979f5790..81d8cf17 100644 --- a/src/ShoppingcartServiceProvider.php +++ b/src/ShoppingcartServiceProvider.php @@ -29,12 +29,12 @@ public function register() } }); - if ( ! class_exists('CreateShoppingcartTable')) { + if (!class_exists('CreateShoppingcartTable')) { // Publish the migration $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__.'/../database/migrations/0000_00_00_000000_create_shoppingcart_table.php' => database_path('migrations/'.$timestamp.'_create_shoppingcart_table.php'), + __DIR__ . '/../database/migrations/0000_00_00_000000_create_shoppingcart_table.php' => database_path('migrations/' . $timestamp . '_create_shoppingcart_table.php'), ], 'migrations'); } } diff --git a/tests/CartTest.php b/tests/CartTest.php index 775e4a83..5d3bd19b 100644 --- a/tests/CartTest.php +++ b/tests/CartTest.php @@ -913,7 +913,7 @@ public function it_will_destroy_the_cart_when_the_user_logs_out_and_the_config_s $user = Mockery::mock(Authenticatable::class); - event(new Logout($user)); + event(new Logout('web', $user)); } /**