96 $candidate = self::reflectCallable($callable);
97 }
catch (\ReflectionException $e) {
101 $byRef = $candidate->returnsReference();
102 $returnType = $candidate->getReturnType();
104 if ($returnType instanceof \ReflectionNamedType) {
105 $typeName = $returnType->getName();
106 $nullable = $returnType->allowsNull();
107 } elseif ($returnType !==
null) {
108 throw new \LogicException(
"Unsupported reflection type " . get_class($returnType));
114 if (!$this->returnType->isSatisfiedBy($typeName, $nullable, $byRef)) {
120 foreach ($candidate->getParameters() as $position => $parameter) {
121 $byRef = $parameter->isPassedByReference();
123 if (($type = $parameter->getType()) instanceof \ReflectionNamedType) {
124 $typeName = $type->getName();
125 $nullable = $type->allowsNull();
126 } elseif ($type !==
null) {
127 throw new \LogicException(
"Unsupported reflection type " . get_class($type));
134 if (isset($this->parameters[$position])) {
135 if (!$this->parameters[$position]->
isSatisfiedBy($typeName, $nullable, $byRef)) {
139 $last = $this->parameters[$position];
144 if (!$parameter->isOptional() && !$parameter->isVariadic()) {
149 if ($last !==
null && $last->isVariadic && !$last->isSatisfiedBy($typeName, $nullable, $byRef)) {
162 $string =
'function ';
164 if ($this->returnType->isByReference) {
171 $l = count($this->parameters) - 1;
172 for (; $i < $l; $i++) {
173 $string .= $this->parameters[$i];
175 if ($o === 0 && !($this->parameters[$i + 1]->isOptional)) {
184 if (isset($this->parameters[$l])) {
185 $string .= $this->parameters[$i] .
' ';
189 $string .= str_repeat(
']', $o) .
' ';
194 if ($this->returnType->typeName !==
null) {
195 $string .=
' : ' . $this->returnType;