diff --git a/src/Basket.php b/src/Basket.php index f01a8b1..749a521 100755 --- a/src/Basket.php +++ b/src/Basket.php @@ -60,9 +60,7 @@ public function __construct(StorageInterface $store, IdentifierInterface $identi $this->id = $this->identifier->get(); // Restore the cart from a saved version - if (method_exists($this->store, 'restore')) { - $this->store->restore(); - } + $this->store->restore(); // Let our storage class know which cart we're talking about $this->store->setIdentifier($this->id); diff --git a/src/Identifier/Cookie.php b/src/Identifier/Cookie.php index 8f9aae7..8a0d3b3 100755 --- a/src/Identifier/Cookie.php +++ b/src/Identifier/Cookie.php @@ -34,7 +34,7 @@ class Cookie implements IdentifierInterface */ public function get(): string { - if (isset($_COOKIE['cart_identifier'])) { + if (! empty($_COOKIE['cart_identifier'])) { return $_COOKIE['cart_identifier']; } diff --git a/src/Identifier/Runtime.php b/src/Identifier/Runtime.php index 443c4e9..6878c7a 100755 --- a/src/Identifier/Runtime.php +++ b/src/Identifier/Runtime.php @@ -28,7 +28,7 @@ class Runtime implements IdentifierInterface { /** @var string */ - protected static $identifier; + protected static string $identifier = ''; /** * Get the current or new unique identifier. @@ -37,7 +37,7 @@ class Runtime implements IdentifierInterface */ public function get(): string { - if (isset(static::$identifier)) { + if (! empty(static::$identifier)) { return static::$identifier; } diff --git a/src/Item.php b/src/Item.php index 5bfa578..1e3ea69 100755 --- a/src/Item.php +++ b/src/Item.php @@ -101,7 +101,7 @@ public function tax(): float $price = $this->totalPrice(); $quantity = $this->quantity; - return (float) $this->tax->rate($price * $quantity); + return $this->tax->rate($price * $quantity); } /** @@ -121,7 +121,7 @@ private function totalPrice(): float } } - return (float) $price; + return $price; } /** @@ -139,7 +139,7 @@ public function total($includeTax = true): float $price = $this->tax->add($price); } - return (float) ($price * $this->quantity); + return ($price * $this->quantity); } /** @@ -177,7 +177,7 @@ public function single($includeTax = true): float $price = $this->tax->add($price); } - return (float) $price; + return $price; } /** diff --git a/src/Storage/Runtime.php b/src/Storage/Runtime.php index 40a8593..0c9bee8 100755 --- a/src/Storage/Runtime.php +++ b/src/Storage/Runtime.php @@ -30,7 +30,7 @@ class Runtime implements StorageInterface { /** @var string */ - protected string $identifier; + protected string $identifier = ''; /** @var array */ protected static array $cart = []; diff --git a/src/Tax.php b/src/Tax.php index 7ef5408..5e30494 100755 --- a/src/Tax.php +++ b/src/Tax.php @@ -41,18 +41,18 @@ class Tax * automatically. * * @param float $value The percentage of your tax (or price before tax) - * @param null $after The value after tax + * @param null|mixed $after The value after tax */ public function __construct(float $value, $after = null) { $this->percentage = $value; if ($after != null && is_numeric($after)) { - $this->percentage = (($after - $value) / $value) * 100; + $this->percentage = (float) ((($after - $value) / $value) * 100); } - $this->deductModifier = 1 - ($this->percentage / 100); - $this->addModifier = 1 + ($this->percentage / 100); + $this->deductModifier = (1 - ($this->percentage / 100)); + $this->addModifier = (1 + ($this->percentage / 100)); } /** @@ -64,7 +64,7 @@ public function __construct(float $value, $after = null) */ public function deduct(float $price): float { - return (float) ($price * $this->deductModifier); + return ($price * $this->deductModifier); } /** @@ -76,7 +76,7 @@ public function deduct(float $price): float */ public function add(float $price): float { - return (float) ($price * $this->addModifier); + return ($price * $this->addModifier); } /** @@ -88,6 +88,6 @@ public function add(float $price): float */ public function rate(float $price): float { - return (float) ($price - $this->deduct($price)); + return ($price - $this->deduct($price)); } }