Beispiel #1
0
 /**
  * Determine if some value fits inside a database column.
  *
  * Right now this check is limited to string values. Future versions might
  * support binary data and numbers as well.
  *
  * @param mixed $content
  * @param string $type
  * @param null $length
  *
  * @throws \SellerLabs\Nucleus\Exceptions\LackOfCoffeeException
  * @return bool
  */
 public static function fits($content, $type, $length = null)
 {
     switch ($type) {
         case static::TYPE_CHAR:
         case static::TYPE_VARCHAR:
             return Std::within(0, Std::coalesce($length, 255), strlen($content));
         case static::TYPE_TINYTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 8), strlen($content));
         case static::TYPE_TEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 16), strlen($content));
         case static::TYPE_MEDIUMTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 24), strlen($content));
         case static::TYPE_LONGTEXT:
             return Std::within(0, Std::coalesce($length, 2 ** 32), strlen($content));
     }
     throw new LackOfCoffeeException('Not implemented.');
 }
Beispiel #2
0
 public function testWithinValidation()
 {
     $this->setExpectedException(LackOfCoffeeException::class);
     Std::within(4000, -1, 34);
 }
Beispiel #3
0
 public function testWithin()
 {
     $this->assertEqualsMatrix([[true, Std::within(0, 12, 3)], [true, Std::within(-40, 12, -5)], [true, Std::within(-100, -20, -40)], [false, Std::within(0.0, 12, 12.0001)], [false, Std::within(-40, 12, -80)], [false, Std::within(-100, -20, 40)]]);
 }