1<?php declare(strict_types = 1);
3namespace DaveRandom\CallbackValidator;
33 private $parameterName;
58 $parameterName = $reflection->getName();
60 if ($reflection->isPassedByReference()) {
64 if ($reflection->isVariadic()) {
68 if ($reflection->isOptional()) {
73 $typeReflection = $reflection->getType();
75 if ($typeReflection instanceof \ReflectionNamedType) {
76 $typeName = $typeReflection->getName();
78 if ($typeReflection->allowsNull()) {
81 } elseif ($typeReflection !==
null) {
82 throw new \LogicException(
"Unsupported reflection type " . get_class($typeReflection));
85 return new self($parameterName, $typeName, $flags);
93 public function __construct($parameterName, $typeName =
null, $flags = self::CONTRAVARIANT)
97 parent::__construct($typeName, $flags, ($flags & self::COVARIANT) !== 0, ($flags & self::CONTRAVARIANT) !== 0);
99 $this->parameterName = (string)$parameterName;
100 $this->isOptional = (bool)($flags & self::OPTIONAL);
101 $this->isVariadic = (bool)($flags & self::VARIADIC);
111 if ($this->typeName !==
null) {
112 if ($this->isNullable) {
116 $string .= $this->typeName .
' ';
119 if ($this->isByReference) {
123 if ($this->isVariadic) {
127 return $string .
'$' . $this->parameterName;
static createFromReflectionParameter($reflection, $flags=0)
__construct($parameterName, $typeName=null, $flags=self::CONTRAVARIANT)