Skip to content

Commit

Permalink
Prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
Harm Smits committed May 15, 2020
1 parent 1ffd61f commit 85e5e19
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 83 deletions.
18 changes: 15 additions & 3 deletions scripts/generate_objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GenerateObjects
private array $types = [
"boolean" => Type::BOOL,
"string" => Type::STRING,
"number" => Type::INT,
"number" => Type::FLOAT,
"integer" => Type::INT,
"array" => Type::ARRAY
];
Expand Down Expand Up @@ -235,6 +235,12 @@ private function setSetterFunction(\Nette\PhpGenerator\ClassType &$class, $name,
}
}

if ($type === "float") {
if (isset($schema["minimum"]) || isset($schema["maximum"])) {
$body .= sprintf("\$this->_checkFloatBounds(%s, %s, %s);\n", "$$name", @$schema["minimum"], @$schema["maximum"]);
}
}

if (isset($schema["enum"])) {
$enums = array_map(function ($item) {
return sprintf("\t\"%s\"", $item);
Expand All @@ -256,10 +262,16 @@ private function setSetterFunction(\Nette\PhpGenerator\ClassType &$class, $name,
* @param array $schema
*/
private function setGetterFunction(\Nette\PhpGenerator\ClassType &$class, $name, array $schema) {
$type = $this->getType($schema);
$method = $class->addmethod("get" . ucfirst($name));
$method->setReturnNullable(true);
$method->setReturnType($this->getType($schema));
$method->setBody(sprintf('return $this->%s;', $name));
$method->setReturnType($type);

if ($type === Type::FLOAT) {
$method->setBody(sprintf('return round($this->%s, 2);', $name));
} else {
$method->setBody(sprintf('return $this->%s;', $name));
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Models/BundlePrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ final class BundlePrice extends \HarmSmits\BolComClient\Objects\AObject
* The price per single unit in case the customer orders at least the quantity
* provided. When using more than 1 price, the respective prices must be in
* decreasing order using 2 decimal precision and dot separated.
* @var int
* @var float
*/
private int $price;
private float $price;


public function getQuantity(): ?int
Expand All @@ -43,15 +43,15 @@ public function setQuantity(int $quantity)
}


public function getPrice(): ?int
public function getPrice(): ?float
{
return $this->price;
return round($this->price, 2);
}


public function setPrice(int $price)
public function setPrice(float $price)
{
$this->_checkIntegerBounds($price, 1, 9999);
$this->_checkFloatBounds($price, 1, 9999);
$this->price = $price;
return $this;
}
Expand Down
50 changes: 25 additions & 25 deletions src/Models/Commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ final class Commission extends \HarmSmits\BolComClient\Objects\AObject

/**
* The price for this product with two decimals precision. The price includes VAT.
* @var int
* @var float
*/
private ?int $price = null;
private ?float $price = null;

/**
* Fixed fee.
* @var int
* @var float
*/
private ?int $fixedAmount = null;
private ?float $fixedAmount = null;

/**
* A percentage of the offer price. The percentage can vary per product category.
* @var int
* @var float
*/
private ?int $percentage = null;
private ?float $percentage = null;

/**
* Total applicable fee calculated based on the offer price provided.
* @var int
* @var float
*/
private ?int $totalCost = null;
private ?float $totalCost = null;

/**
* Total applicable fee calculated based on the offer price if you do not meet the
* maximum price criteria.
* @var int
* @var float
*/
private ?int $totalCostWithoutReduction = null;
private ?float $totalCostWithoutReduction = null;

/** @var Reduction[] */
private array $reductions = [];
Expand Down Expand Up @@ -85,65 +85,65 @@ public function setCondition(string $condition)
}


public function getPrice(): ?int
public function getPrice(): ?float
{
return $this->price;
return round($this->price, 2);
}


public function setPrice(int $price)
public function setPrice(float $price)
{
$this->price = $price;
return $this;
}


public function getFixedAmount(): ?int
public function getFixedAmount(): ?float
{
return $this->fixedAmount;
return round($this->fixedAmount, 2);
}


public function setFixedAmount(int $fixedAmount)
public function setFixedAmount(float $fixedAmount)
{
$this->fixedAmount = $fixedAmount;
return $this;
}


public function getPercentage(): ?int
public function getPercentage(): ?float
{
return $this->percentage;
return round($this->percentage, 1);
}


public function setPercentage(int $percentage)
public function setPercentage(float $percentage)
{
$this->percentage = $percentage;
return $this;
}


public function getTotalCost(): ?int
public function getTotalCost(): ?float
{
return $this->totalCost;
return round($this->totalCost, 2);
}


public function setTotalCost(int $totalCost)
public function setTotalCost(float $totalCost)
{
$this->totalCost = $totalCost;
return $this;
}


public function getTotalCostWithoutReduction(): ?int
public function getTotalCostWithoutReduction(): ?float
{
return $this->totalCostWithoutReduction;
return round($this->totalCostWithoutReduction, 2);
}


public function setTotalCostWithoutReduction(int $totalCostWithoutReduction)
public function setTotalCostWithoutReduction(float $totalCostWithoutReduction)
{
$this->totalCostWithoutReduction = $totalCostWithoutReduction;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Norm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class Norm extends \HarmSmits\BolComClient\Objects\AObject

/**
* Service norm for this indicator.
* @var int
* @var float
*/
private ?int $value = null;
private ?float $value = null;


public function getCondition(): ?string
Expand All @@ -38,13 +38,13 @@ public function setCondition(string $condition)
}


public function getValue(): ?int
public function getValue(): ?float
{
return $this->value;
return round($this->value, 1);
}


public function setValue(int $value)
public function setValue(float $value)
{
$this->value = $value;
return $this;
Expand Down
30 changes: 15 additions & 15 deletions src/Models/PurchasableShippingLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ final class PurchasableShippingLabel extends \HarmSmits\BolComClient\Objects\AOb

/**
* The price the item has been sold for.
* @var int
* @var float
*/
private ?int $retailerPrice = null;
private ?float $retailerPrice = null;

/**
* The price that is charged to the partner for the shipping label, including VAT.
* @var int
* @var float
*/
private ?int $purchasePrice = null;
private ?float $purchasePrice = null;

/**
* The discount of the item that has been sold.
* @var int
* @var float
*/
private ?int $discount = null;
private ?float $discount = null;

/**
* A unique code referring to the used shipping label for this shipment.
Expand Down Expand Up @@ -113,39 +113,39 @@ public function setMaxDimensions(string $maxDimensions)
}


public function getRetailerPrice(): ?int
public function getRetailerPrice(): ?float
{
return $this->retailerPrice;
return round($this->retailerPrice, 2);
}


public function setRetailerPrice(int $retailerPrice)
public function setRetailerPrice(float $retailerPrice)
{
$this->retailerPrice = $retailerPrice;
return $this;
}


public function getPurchasePrice(): ?int
public function getPurchasePrice(): ?float
{
return $this->purchasePrice;
return round($this->purchasePrice, 2);
}


public function setPurchasePrice(int $purchasePrice)
public function setPurchasePrice(float $purchasePrice)
{
$this->purchasePrice = $purchasePrice;
return $this;
}


public function getDiscount(): ?int
public function getDiscount(): ?float
{
return $this->discount;
return round($this->discount, 2);
}


public function setDiscount(int $discount)
public function setDiscount(float $discount)
{
$this->discount = $discount;
return $this;
Expand Down
16 changes: 8 additions & 8 deletions src/Models/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ final class Score extends \HarmSmits\BolComClient\Objects\AObject

/**
* The score for this measurement (denominator divided by the numerator).
* @var int
* @var float
*/
private ?int $value = null;
private ?float $value = null;

/**
* The difference between the score and the bol.com service norm.
* @var int
* @var float
*/
private ?int $distanceToNorm = null;
private ?float $distanceToNorm = null;


public function getConforms(): ?bool
Expand Down Expand Up @@ -84,26 +84,26 @@ public function setDenominator(int $denominator)
}


public function getValue(): ?int
public function getValue(): ?float
{
return $this->value;
}


public function setValue(int $value)
public function setValue(float $value)
{
$this->value = $value;
return $this;
}


public function getDistanceToNorm(): ?int
public function getDistanceToNorm(): ?float
{
return $this->distanceToNorm;
}


public function setDistanceToNorm(int $distanceToNorm)
public function setDistanceToNorm(float $distanceToNorm)
{
$this->distanceToNorm = $distanceToNorm;
return $this;
Expand Down
14 changes: 14 additions & 0 deletions src/Objects/AObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ protected function _checkIntegerBounds(int $check, int $min, int $max) {
throw new InvalidArgumentException("Integer is not in correct range");
}

/**
* Check if a float is in the correct range
*
* @param float $check
* @param float $min
* @param float $max
*
* @throws \HarmSmits\BolComClient\Exception\InvalidArgumentException
*/
protected function _checkFloatBounds(float $check, float $min, float $max) {
if ($check < $min || $check > $max)
throw new InvalidArgumentException("Float is not in correct range");
}

/**
* Apply default value
*
Expand Down
Loading

0 comments on commit 85e5e19

Please sign in to comment.