88 $candidate = self::reflectCallable($callable);
89 }
catch (\ReflectionException $e) {
93 $byRef = $candidate->returnsReference();
94 $returnType = $candidate->getReturnType();
96 if ($returnType instanceof \ReflectionNamedType) {
97 $typeName = $returnType->getName();
98 $nullable = $returnType->allowsNull();
99 } elseif ($returnType !==
null) {
100 throw new \LogicException(
"Unsupported reflection type " . get_class($returnType));
106 if (!$this->returnType->isSatisfiedBy($typeName, $nullable, $byRef)) {
112 foreach ($candidate->getParameters() as $position => $parameter) {
113 $byRef = $parameter->isPassedByReference();
115 if (($type = $parameter->getType()) instanceof \ReflectionNamedType) {
116 $typeName = $type->getName();
117 $nullable = $type->allowsNull();
118 } elseif ($type !==
null) {
119 throw new \LogicException(
"Unsupported reflection type " . get_class($type));
126 if (isset($this->parameters[$position])) {
127 if (!$this->parameters[$position]->
isSatisfiedBy($typeName, $nullable, $byRef)) {
131 $last = $this->parameters[$position];
136 if (!$parameter->isOptional() && !$parameter->isVariadic()) {
141 if ($last !==
null && $last->isVariadic && !$last->isSatisfiedBy($typeName, $nullable, $byRef)) {
154 $string =
'function ';
156 if ($this->returnType->isByReference) {
163 $l = count($this->parameters) - 1;
164 for (; $i < $l; $i++) {
165 $string .= $this->parameters[$i];
167 if ($o === 0 && !($this->parameters[$i + 1]->isOptional)) {
176 if (isset($this->parameters[$l])) {
177 $string .= $this->parameters[$i] .
' ';
181 $string .= str_repeat(
']', $o) .
' ';
186 if ($this->returnType->typeName !==
null) {
187 $string .=
' : ' . $this->returnType;