PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
ReturnType.php
1<?php declare(strict_types = 1);
2
3namespace DaveRandom\CallbackValidator;
4
5final class ReturnType extends Type
6{
11 const CONTRAVARIANT = 0x01 << 16;
12
16 const COVARIANT = 0x02 << 16;
17
23 public static function createFromReflectionFunctionAbstract($reflection, $flags = 0)
24 {
25 if ($reflection->returnsReference()) {
26 $flags |= self::REFERENCE;
27 }
28
29 $typeName = null;
30 $typeReflection = $reflection->getReturnType();
31
32 if ($typeReflection instanceof \ReflectionNamedType) {
33 $typeName = $typeReflection->getName();
34
35 if ($typeReflection->allowsNull()) {
36 $flags |= self::NULLABLE;
37 }
38 } elseif ($typeReflection !== null) {
39 throw new \LogicException("Unsupported reflection type " . get_class($typeReflection));
40 }
41
42 return new self($typeName, $flags);
43 }
44
49 public function __construct($typeName = null, $flags = self::COVARIANT)
50 {
51 $flags = (int)$flags;
52
53 parent::__construct($typeName, $flags, ($flags & self::COVARIANT) !== 0, ($flags & self::CONTRAVARIANT) !== 0);
54 }
55
59 public function __toString()
60 {
61 return $this->isNullable && $this->typeName !== null
62 ? '?' . $this->typeName
63 : (string)$this->typeName;
64 }
65}
__construct($typeName=null, $flags=self::COVARIANT)
Definition: ReturnType.php:49
static createFromReflectionFunctionAbstract($reflection, $flags=0)
Definition: ReturnType.php:23