/** * * @param string $text * @param int $type * * @throws \Exception if maximum number of items reached * * @return \sfAltumoPlugin\Geckoboard\Widget\TextWidget */ public function addItem($text, $type = self::TYPE_NONE) { $item = new \stdClass(); // pre-validate and set text $item->text = \Altumo\Validation\Strings::assertString($text); // pre-validate and set type $item->type = \Altumo\Validation\Numerics::assertInteger($type); if (count($this->getItems()) > self::MAXIMUM_ITEM_COUNT - 1) { throw new \Exception("Cannot add new item, maximum count reached"); } // add to items $this->items[] = $item; return $this; }
/** * Tests Numerics::assertInteger() * */ public function testAssertInteger() { $input = '7215'; $output = \Altumo\Validation\Numerics::assertInteger($input); $this->assertTrue(is_integer($output)); $input = 7215.0; $output = \Altumo\Validation\Numerics::assertInteger($input); $this->assertTrue(is_integer($output)); $input = 7215; $output = \Altumo\Validation\Numerics::assertInteger($input); $this->assertTrue(is_integer($output)); try { $input = 72.56; $output = \Altumo\Validation\Numerics::assertInteger($input); $this->assertTrue(false); } catch (\Exception $e) { $this->assertTrue(true); } $input = 0; $output = \Altumo\Validation\Numerics::assertInteger($input); $this->assertTrue(is_integer($output)); }
/** * Converts cents to dollars. * * * @param int $amount * * @return float */ static function getCentsAsDollars($amount) { $amount = \Altumo\Validation\Numerics::assertInteger($amount); return $amount / 100; }
/** * Sets the offset for retrieved data * * @param integer $offset * * @return RawQuery Returns itself */ public function setOffset($offset) { $this->offset = \Altumo\Validation\Numerics::assertInteger($offset); return $this; }