Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cjonstrup committed Jan 10, 2021
1 parent 63343b6 commit 8190138
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/Basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Identifier/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Identifier/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class Runtime implements IdentifierInterface
{
/** @var string */
protected static $identifier;
protected static string $identifier = '';

/**
* Get the current or new unique identifier.
Expand All @@ -37,7 +37,7 @@ class Runtime implements IdentifierInterface
*/
public function get(): string
{
if (isset(static::$identifier)) {
if (! empty(static::$identifier)) {
return static::$identifier;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -121,7 +121,7 @@ private function totalPrice(): float
}
}

return (float) $price;
return $price;
}

/**
Expand All @@ -139,7 +139,7 @@ public function total($includeTax = true): float
$price = $this->tax->add($price);
}

return (float) ($price * $this->quantity);
return ($price * $this->quantity);
}

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ public function single($includeTax = true): float
$price = $this->tax->add($price);
}

return (float) $price;
return $price;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class Runtime implements StorageInterface
{
/** @var string */
protected string $identifier;
protected string $identifier = '';

/** @var array */
protected static array $cart = [];
Expand Down
14 changes: 7 additions & 7 deletions src/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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));
}
}

0 comments on commit 8190138

Please sign in to comment.