示例#1
0
 /**
  * @param Type $type
  * @return int|float|bool|string|array|object|null
  */
 private function getValueForType(Type $type)
 {
     if ($type instanceof IntegerType) {
         return 0;
     } else {
         if ($type instanceof FloatType) {
             return 0.0;
         } else {
             if ($type instanceof BooleanType) {
                 return false;
             } else {
                 if ($type instanceof StringType) {
                     return '';
                 } else {
                     if ($type instanceof ArrayType) {
                         return array();
                     } else {
                         if ($type instanceof MultiType) {
                             return $this->getValueForType($type->getTypes()[0]);
                         } else {
                             if ($type instanceof ClassType) {
                                 return (new Mockster($type->getClass(), $this->factory))->mock();
                             } else {
                                 return null;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public function is($value)
 {
     if (!is_array($value)) {
         return false;
     }
     foreach ($value as $item) {
         if (!$this->itemType->is($item)) {
             return false;
         }
     }
     return true;
 }
示例#3
0
 /**
  * @param ArrayType|Type $type
  * @param mixed $value
  * @return TypedValue
  */
 private function typedItem(Type $type, $value)
 {
     return new TypedValue($value, $type->getItemType());
 }
示例#4
0
 /**
  * @param mixed $value
  * @return boolean
  */
 public function is($value)
 {
     return $this->primitive->is($value);
 }
示例#5
0
 private function toString(Type $type)
 {
     if ($type instanceof ClassType) {
         return (new \ReflectionClass($type->getClass()))->getShortName();
     } else {
         return (string) $type;
     }
 }
 /**
  * @param Type|NullableType $type
  * @return Type
  */
 private function getInnerType(Type $type)
 {
     return $type->getType();
 }
示例#7
0
 public function is($value)
 {
     return is_null($value) || $this->type->is($value);
 }
示例#8
0
 private function objectOfRightClass(Type $type, $object)
 {
     return $type instanceof ClassType && is_object($object) && $type->getClass() == get_class($object);
 }