Example #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;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #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;
 }
Example #3
0
 /**
  * @param ArrayType|Type $type
  * @param mixed $value
  * @return TypedValue
  */
 private function typedItem(Type $type, $value)
 {
     return new TypedValue($value, $type->getItemType());
 }
Example #4
0
 /**
  * @param mixed $value
  * @return boolean
  */
 public function is($value)
 {
     return $this->primitive->is($value);
 }
Example #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();
 }
Example #7
0
 public function is($value)
 {
     return is_null($value) || $this->type->is($value);
 }
Example #8
0
 private function objectOfRightClass(Type $type, $object)
 {
     return $type instanceof ClassType && is_object($object) && $type->getClass() == get_class($object);
 }