/** * Creates new Tax from a upper decimal value. * I.e. value must be '1.22' for a tax of '22%'. * * @param double $lowerDecimal * @return Tax * @throws InvalidArgumentException */ public static function fromUpperDecimal($upperDecimal) { if (!is_double($upperDecimal)) { throw new InvalidArgumentException('$upperDecimal must be a double, but ' . $upperDecimal . ' given.'); } return new TaxImpl($upperDecimal); }
public function testGetPaymentTypes() { $cougarCashClient = new \clients\cougar_cash(); $result = $cougarCashClient->getPaymentTypes(); if (count($result->{"payment_types"}) > 0) { foreach ($result->{"payment_types"} as $paymentType) { if ($paymentType->{"account_type"} == "CREDIT_CARD") { $this->assertTrue(is_string($paymentType->{"id"})); $this->assertTrue(is_string($paymentType->{"nickname"})); $this->assertTrue(is_string($paymentType->{"munged_account_num"})); $this->assertTrue(substr($paymentType->{"munged_account_num"}, 0, 1) === "*"); $this->assertTrue(is_string($paymentType->{"financial_institution"})); $this->assertTrue(is_int($paymentType->{"minimum"})); $this->assertTrue(is_int($paymentType->{"maximum"})); $this->assertTrue(is_double($paymentType->{"min_fee"})); $this->assertTrue(is_double($paymentType->{"fee_percent"})); } elseif ($paymentType->{"account_type"} == "BANK_ACCOUNT") { $this->assertTrue(is_string($paymentType->{"id"})); $this->assertTrue(is_string($paymentType->{"nickname"})); $this->assertTrue(is_string($paymentType->{"munged_account_num"})); $this->assertTrue(substr($paymentType->{"munged_account_num"}, 0, 1) === "*"); $this->assertTrue(is_string($paymentType->{"financial_institution"})); $this->assertTrue(is_int($paymentType->{"minimum"})); $this->assertTrue(is_int($paymentType->{"maximum"})); } } } }
public function testCanSearchAddress() { $latAndLong = $this->geocoder->getGeocodedLatitudeAndLongitude('12 Girouard, Montreal, Quebec'); $this->assertTrue(is_array($latAndLong)); $this->assertTrue(is_double($latAndLong[0])); $this->assertTrue(is_double($latAndLong[1])); }
protected function recursiveQuote($val) { if (is_array($val)) { $return = array(); foreach ($val as $v) { $return[] = $this->recursiveQuote($v); } return '(' . implode(',', $return) . ')'; } else { if (is_null($val)) { $val = 'NULL'; } else { if (is_int($val)) { $val = (int) $val; } else { if (is_double($val)) { $val = (double) $val; } else { if (is_float($val)) { $val = (double) $val; } else { $val = "'" . Convert::raw2sql($val) . "'"; } } } } } return $val; }
/** * @param $sql * @param $params * @return mixed */ private function prepare($sql, $params) { $escaped = ''; if ($params) { foreach ($params as $key => $value) { if (is_bool($value)) { $value = $value ? 1 : 0; } elseif (is_double($value)) { $value = str_replace(',', '.', $value); } elseif (is_numeric($value)) { if (is_string($value)) { $value = "'" . $this->provider->escape($value) . "'"; } else { $value = $this->provider->escape($value); } } elseif (is_null($value)) { $value = "NULL"; } else { $value = "'" . $this->provider->escape($value) . "'"; } $escaped[] = $value; } } $this->params = $escaped; $q = preg_replace_callback("/(\\?)/i", array($this, "replaceParams"), $sql); return $q; }
public function isHourValid($hour) { if (!is_numeric($hour) || is_double($hour) || $hour < 0) { return false; } return true; }
public function where($where, $val = null) { $where = $this->escape($where); if ($val === true) { $this->where_list[] = $where . " = 'TRUE'"; } else { if ($val === false) { $this->where_list[] = $where . " = 'FALSE'"; } else { if ($val === null) { $this->where_list[] = $where; } else { if (is_string($val)) { $this->where_list[] = $where . " = '" . $this->escape($val) . "'"; } else { if (is_int($val) || is_float($val) || is_double($val)) { $this->where_list[] = $where . ' = ' . $this->escape($val); } else { $this->where_list[] = $where . " = '" . $this->escape($val) . "'"; # default } } } } } }
public function testCGet() { $client = static::createClient(); $crawler = $client->request('GET', '/api/charges'); $this->assertTrue($client->getResponse()->headers->contains('Content-Type', 'application/json')); $json = json_decode($client->getResponse()->getContent()); $this->assertNotNull($json, $client->getResponse()->getContent()); $this->assertEquals($json->{'error'}, "success"); $this->assertInternalType("array", $json->{'charges'}); foreach ($json->{'charges'} as $charge) { $this->assertInternalType("integer", $charge->{'id'}); if (property_exists($charge, 'description')) { $this->assertInternalType("string", $charge->{'description'}); } if (is_double($charge->{'duration'})) { $this->assertInternalType("float", $charge->{'duration'}); } else { $this->assertInternalType("integer", $charge->{'duration'}); } $this->assertInternalType("string", $charge->{'created'}); $this->assertInternalType("object", $charge->{'employee'}); $this->assertInternalType("object", $charge->{'task'}); $this->assertFalse(date_create($charge->{'created'}) === FALSE); } $client->insulate(); }
/** * @param double $value * @throws Exception */ public function __construct($value) { if (!is_double($value)) { throw new Exception('Incoming value must be of type double.'); } $this->_value = $value; }
/** * Asserts that two variables are equal. * * @param mixed $expected * @param mixed $actual * @param mixed $delta * @param string $message * @access public * @static */ public static function assertEquals($expected, $actual, $delta = 0, $message = '') { if (is_null($expected) && is_null($actual)) { return; } if (is_object($expected)) { if (!is_object($actual) || serialize($expected) != serialize($actual)) { self::failNotEquals($expected, $actual, $message); } return; } if (is_array($expected)) { if (!is_array($actual)) { self::failNotEquals($expected, $actual, $message); } self::sortArrayRecursively($actual); self::sortArrayRecursively($expected); if (self::$looselyTyped) { $actual = self::convertToString($actual); $expected = self::convertToString($expected); } self::assertEquals(serialize($expected), serialize($actual)); return; } if ((is_double($expected) || is_float($expected)) && (is_double($actual) || is_float($actual))) { if (!(abs($expected - $actual) <= $delta)) { self::failNotEquals($expected, $actual, $message); } return; } if (self::$looselyTyped) { settype($actual, gettype($expected)); } self::assertSame($expected, $actual, $message); }
/** * This method adds the passed object with the passed key * to the HashMap. * * @param mixed $key The key to add the passed value under * @param mixed $object The object to add to the HashMap * * @return \AppserverIo\Collections\HashMap The instance * @throws \AppserverIo\Collections\InvalidKeyException Is thrown if the passed key is NOT an primitive datatype * @throws \AppserverIo\Lang\NullPointerException Is thrown if the passed key is null or not a flat datatype like Integer, Strng, Double or Boolean */ public function add($key, $object) { if (is_null($key)) { throw new NullPointerException('Passed key is null'); } // check if a primitive datatype is passed if (is_integer($key) || is_string($key) || is_double($key) || is_bool($key)) { // add the item to the array $this->items[$key] = $object; // and return return; } // check if an object is passed if (is_object($key)) { if ($key instanceof Strng) { $newKey = $key->stringValue(); } elseif ($key instanceof Flt) { $newKey = $key->floatValue(); } elseif ($key instanceof Integer) { $newKey = $key->intValue(); } elseif ($key instanceof Boolean) { $newKey = $key->booleanValue(); } elseif (method_exists($key, '__toString')) { $newKey = $key->__toString(); } else { throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method'); } // add the item to the array $this->items[$newKey] = $object; // and return return; } throw new InvalidKeyException('Passed key has to be a primitive datatype or has to implement the __toString() method'); }
public function unary($la) { for ($i = 0; $i < 3; $i++) { foreach ($la as $l) { if (is_int($l)) { echo "{$l} is_int\n"; } if (is_string($l)) { echo "{$l} is_string\n"; } if (is_double($l)) { echo "{$l} is_double\n"; } if (is_null($l)) { echo "{$l} is_null\n"; } if (is_double($l)) { echo "{$l} is_double\n"; } if (is_array($l)) { echo "{$l} is_array\n"; } if (is_object($l)) { echo "{$l} is_object\n"; } } } }
private function AddParameter(&$params, &$types, $this_param) { if (is_array($this_param) === true && count($this_param) > 0) { // recurse into any number of nested arrays as necessary foreach ($this_param as $this_parameter) { self::AddParameter($params, $types, $this_parameter); } } else { if (is_string($this_param)) { $types[] = 's'; } else { if (is_int($this_param)) { $types[] = 'i'; } else { if (is_double($this_param)) { $types[] = 'd'; } else { $types[] = 's'; // string as default } } } $params[] = $this_param; } }
public function query($query, $parameters = NULL) { $this->open_connection(); $statement = $this->conn->prepare($query); if ($statement) { if (!is_null($parameters) && count($parameters) > 0) { foreach ($parameters as $parameter) { if (is_integer($parameter)) { $statement->bind_param("i", $parameter); } elseif (is_double($parameter)) { $statement->bind_param("d", $parameter); } elseif (is_string($parameter)) { $statement->bind_param("s", $parameter); } } } $statement->execute(); $result = $statement->get_result(); $statement->close(); } else { $log->error("Error preparing statement of query " . $query); } $this->close_connection(); return $result; }
protected function _xmlType($value) { if (is_string($value)) { return "<string>{$value}</string>"; } else { if (is_int($value)) { return "<int>{$value}</int>"; } else { if (is_double($value)) { return "<double>{$value}</double>"; } else { if (is_array($value) && count($value) > 0) { $r = "<struct>\n"; foreach ($value as $n => $v) { $r .= "\t<member>\n"; $r .= "\t\t<name>{$n}</name>\n"; $r .= "\t\t<value>{$this->_xmlType($v)}</value>\n"; $r .= "\t</member>\n"; } return "{$r}\n</struct>\n"; } } } } return "<string><![[{$value}]]></string>"; }
public function isScalar() { if (!is_float($this->getContent()) || !is_double($this->getContent())) { $this->add(ErrorCode::MUST_BE_SCALAR_ERROR_CODE); } return $this; }
/** * Compute chiSquare test value from array of observations * and expected probabilities of slots. * * @param array(int) $observedCnt observed counts * @param array(double) $expectedProb expected probabilities * * @returns double chi squared */ static function chiSquare(array $observedCnt, array $expectedProb) { Preconditions::check(count($observedCnt) == count($expectedProb), "number of slots for observations and expectations should match."); foreach ($observedCnt as $cnt) { Preconditions::check(is_int($cnt), "Observed count should be integer"); } foreach ($expectedProb as $prob) { Preconditions::check(is_double($prob), "Probability should be double"); Preconditions::check(0.0 < $prob && 1.0 > $prob, "Expected probabilities shoud be in range (0,1)."); } Preconditions::check(abs(array_sum($expectedProb) - 1) < 1.0E-6, "Probabilities does not sum up to 1"); $samples = array_sum($observedCnt); foreach ($expectedProb as $prob) { if ($samples * $prob <= 5) { // @see http://en.wikipedia.org/wiki/Pearson's_chi-square_test#Problems throw new RuntimeException("You should have more samples for " . "computing Pearson test with specified probabilities"); } } $chisqr = 0; for ($i = 0; $i < count($observedCnt); $i++) { $expected = $expectedProb[$i] * $samples; $chisqr += Math::sqr($observedCnt[$i] - $expected) / $expected; } return $chisqr; }
public function set($value) { if (!is_double($value)) { throw new \InvalidArgumentException('Expected double value'); } $this->value = $value; }
function showItems() { if (count($_SESSION['cart']) == 0) { echo "cart is empty"; } else { $cart = $_SESSION['cart']; echo "<table border=1>"; echo "<tr>"; echo "<td>Product_id</td>"; echo "<td>Product_name</td>"; echo "<td>Product_quantity</td>"; echo "<td>Product_price</td>"; echo "<td>Total_price</td>"; echo "</tr>"; for ($i = 0; $i < count($cart); $i++) { echo "<tr>"; for ($j = 0; $j < count($cart[$i]); $j++) { echo "<td>"; echo $cart[$i][$j] . " "; echo "</td>"; if (is_double($cart[$i][$j])) { $totalcartprice = $totalcartprice + $cart[$i][$j + 1]; } } echo "</tr>"; } echo "cart_price: " . $totalcartprice; echo "</table>"; } }
/** * Check whether or not $value is a Float object. * * @throws \InvalidArgumentException If $value is not an instance of Float. */ protected function checkType($value) { if (is_double($value) !== true) { $msg = "The Float Datatype only accepts to store float values."; throw new InvalidArgumentException($msg); } }
/** * @covers Fisharebest\PhpPolyfill\Php::inf * @covers Fisharebest\PhpPolyfill\Php::isLittleEndian * @runInSeparateProcess */ public function testInf() { $this->assertTrue(is_float(Php::inf())); $this->assertTrue(is_double(Php::inf())); $this->assertTrue(is_infinite(Php::inf())); $this->assertFalse(is_finite(Php::inf())); }
/** * display - displays a receipt * * @param \Cilex\Store\Products $products - products to be displayed * @param double $subtotal - subtotal of the transaction * @param double $total - total value of the transaction * @param double $discount - dicount value applied to transaction * @return string */ public static function display(\Cilex\Store\Products $products, $subtotal, $total, $discount = null) { $text = array(); $text[] = PHP_EOL . '----------Receipt ' . gmdate('d-m-Y', time()) . '------------' . PHP_EOL; $text[] = '----------------Products----------------' . PHP_EOL; //products if (!empty($products->getProperties())) { foreach ($products->getProperties() as $product => $value) { $valueFormatted = is_double($value) ? money_format('%.2n', $value) : $value; //set text $text[] = ucwords(str_replace('-', ' ', $product)) . ' [' . $valueFormatted . ']'; } } else { $text[] = 'There are no products to display!'; } //subtotal $subtotalFormatted = is_double($subtotal) ? money_format('%.2n', $subtotal) : $subtotal; $text[] = PHP_EOL . '------------------------' . PHP_EOL; $text[] = 'SubTotal [' . $subtotalFormatted . ']'; //discount $discountFormatted = is_double($discount) ? money_format('%.2n', $discount) : $discount; if ($discount !== null) { $text[] = PHP_EOL . '------------------------' . PHP_EOL; $text[] = 'Discount [' . $discountFormatted . ']'; } //total $totalFormatted = is_double($total) ? money_format('%.2n', $total) : $total; $text[] = PHP_EOL . '------------------------' . PHP_EOL; $text[] = 'Total [' . $totalFormatted . ']' . PHP_EOL; return $text; }
/** * @param double $value */ public function __construct($value) { if (!is_double($value)) { throw new \InvalidArgumentException('Coordinate value should be of type double.'); } $this->value = $value; }
public function __construct($_ = 0.0) { if (is_double($_) != true) { throw new \Exception(); } parent::__construct($_); }
/** * @param $value * @return bool */ private function check($value) { if ($this->type != self::$TYPE_ALL) { if ($this->type == self::$TYPE_NUMBER && !is_numeric($value)) { return false; } else { if (($this->type == self::$TYPE_INT || $this->type == self::$TYPE_NUMBER) && !is_integer($value)) { return false; } else { if ($this->type == self::$TYPE_NUMBER && !is_double($value)) { return false; } else { if ($this->type == self::$TYPE_ARRAY && !is_array($value)) { return false; } else { if ($this->type == self::$TYPE_OBJECT) { if (!is_object($value)) { return false; } else { if ($this->object_type && !$value instanceof $this->object_type) { return false; } } } else { if ($this->type == self::$TYPE_STRING && !is_string($value)) { return false; } } } } } } } return true; }
/** * @param mixed $value * @return string */ public function getString($value) { if (is_string($value)) { return $this->fromString($value); } if (is_int($value)) { return $this->fromInt($value); } if (is_double($value)) { return $this->fromDouble($value); } if (is_bool($value)) { return $this->fromBoolean($value); } if ($value instanceof \DateTime) { return $this->fromDateTime($value); } if ($value instanceof \Traversable || is_array($value)) { return $this->fromIterable($value); } if (is_object($value)) { return $this->fromIterable($value); } if (empty($value)) { return $this->fromEmpty(); } return $this->fromOther(); }
/** * Check if value is valid for the given property * * @param string $property Name of property * @param mixed $value Value to test * * @return boolean * @throws RangeException if the value dos not fit the specified size * @throws InvalidArgumentException if the value dos not mathc the property declartion */ protected function isValidType($property, $value) { $type = $this->propertyType($property); $value = is_numeric($value) ? $value + 1 - 1 : $value; //Force to be a number if ($type == 'integer' && is_numeric($value) && preg_match('/^[0-9]+$/', $value)) { $this->isValidLength($property, $value); return true; } elseif ($type == 'float' && is_float($value)) { return true; } elseif ($type == 'double' && is_double($value)) { return true; } elseif ($type == 'boolean' && is_bool($value)) { return true; } elseif ($type == 'string') { if (is_string($value) || is_float($value) || is_integer($value) || is_bool($value)) { $this->isValidLength($property, $value); return true; } } elseif ($type == 'array' && is_array($value)) { return true; } elseif ($type == 'mixed') { return true; } elseif ($value instanceof $type) { return true; } else { $message = 'Input:\'' . $value . '\' of type \'' . gettype($value) . '\' does not match property declartion [' . $type . ' $' . $property . ']'; throw new InvalidArgumentException($message, 1); } }
/** * @param $value * * @return bool|null */ function tril($value) { if (null === $value || false === $value || true === $value) { return $value; } if (is_array($value)) { return !empty($value); } if (is_object($value)) { return true; } if (is_double($value) && is_nan($value)) { return null; } $value = trim(strtolower($value)); if (in_array($value, ['', 'null', 'maybe'])) { return null; } if (in_array($value, ['no', 'off', '0', 'false'])) { return false; } if (in_array($value, ['yes', 'on', '1', 'true'])) { return true; } return boolval($value); }
/** * Try to figure out what type our data has. */ function calculateType() { if ($this->data === true || $this->data === false) { return 'boolean'; } if (is_integer($this->data)) { return 'int'; } if (is_double($this->data)) { return 'double'; } // Deal with XMLRPC object types base64 and date if (is_object($this->data) && $this->data instanceof XMLRPC_Date) { return 'date'; } if (is_object($this->data) && $this->data instanceof XMLRPC_Base64) { return 'base64'; } // If it is a normal PHP object convert it in to a struct if (is_object($this->data)) { $this->data = get_object_vars($this->data); return 'struct'; } if (!is_array($this->data)) { return 'string'; } /* We have an array - is it an array or a struct ? */ if ($this->isStruct($this->data)) { return 'struct'; } else { return 'array'; } }
/** * Write a scalar value into the current stream. * * If the given value is a string, it will be output surrounded by double quotes (") characters. * * @param mixed $scalar A PHP scalar value or null. * @throws InvalidArgumentException If $scalar is not a PHP scalar value nor null. * @throws StreamAccessException If an error occurs while writing the scalar value. */ public function writeScalar($scalar) { if (Utils::isScalar($scalar) === false) { $msg = "A '" . gettype($scalar) . "' value is not a PHP scalar value nor null."; throw new InvalidArgumentException($msg); } try { if (is_int($scalar) === true) { $this->getStream()->write($scalar); } else { if (is_double($scalar) === true) { if (strpos('' . $scalar, '.') === false) { $scalar = $scalar . '.0'; } $this->getStream()->write($scalar); } else { if (is_string($scalar) === true) { $this->getStream()->write(PhpUtils::doubleQuotedPhpString($scalar)); } else { if (is_bool($scalar) === true) { $this->getStream()->write($scalar === true ? 'true' : 'false'); } else { if (is_null($scalar) === true) { $this->getStream()->write('null'); } } } } } } catch (StreamException $e) { $msg = "An error occured while writing the scalar value '{$scalar}'."; throw new StreamAccessException($msg, $this, 0, $e); } }