/** * Decreases the stock level. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @api * @param float $step The value the stock level should be decreased, default value is 1. * @return float|null The new stock level of the product. */ public function decreaseStockLevel($step = 1.0) { $this->getStockLevel(); // cast int to float if (InputValidator::isInt($step)) { $step = (double) $step; } if (!InputValidator::isRangedFloat($step, 0.0)) { return $this->stockLevel; } $this->changeStockLevel((double) $step * -1); return $this->stockLevel; }
/** * @group utility */ function testIsRangedFloat() { $this->assertFalse(InputValidator::isRangedFloat("Some String")); $this->assertFalse(InputValidator::isRangedFloat(3)); $this->assertFalse(InputValidator::isRangedFloat(null)); $this->assertTrue(InputValidator::isRangedFloat(1.2)); $this->assertTrue(InputValidator::isRangedFloat(1.2, 0.0)); $this->assertFalse(InputValidator::isRangedFloat(1.2, 2.0)); $this->assertTrue(InputValidator::isRangedFloat(1.2, 0.0, 12.0)); $this->assertFalse(InputValidator::isRangedFloat(1.2, 2.0, 12.0)); $this->assertTrue(InputValidator::isRangedFloat(1.2, null, 12.0)); $this->assertFalse(InputValidator::isRangedFloat(1.2, null, -1.0)); }