login consent app sql
This commit is contained in:
192
vendor/symfony/property-info/Util/PhpDocTypeHelper.php
vendored
Normal file
192
vendor/symfony/property-info/Util/PhpDocTypeHelper.php
vendored
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyInfo\Util;
|
||||
|
||||
use phpDocumentor\Reflection\PseudoTypes\List_;
|
||||
use phpDocumentor\Reflection\Type as DocType;
|
||||
use phpDocumentor\Reflection\Types\Array_;
|
||||
use phpDocumentor\Reflection\Types\Collection;
|
||||
use phpDocumentor\Reflection\Types\Compound;
|
||||
use phpDocumentor\Reflection\Types\Null_;
|
||||
use phpDocumentor\Reflection\Types\Nullable;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
// Workaround for phpdocumentor/type-resolver < 1.6
|
||||
// We trigger the autoloader here, so we don't need to trigger it inside the loop later.
|
||||
class_exists(List_::class);
|
||||
|
||||
/**
|
||||
* Transforms a php doc type to a {@link Type} instance.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @author Guilhem N. <egetick@gmail.com>
|
||||
*/
|
||||
final class PhpDocTypeHelper
|
||||
{
|
||||
/**
|
||||
* Creates a {@see Type} from a PHPDoc type.
|
||||
*
|
||||
* @return Type[]
|
||||
*/
|
||||
public function getTypes(DocType $varType): array
|
||||
{
|
||||
$types = [];
|
||||
$nullable = false;
|
||||
|
||||
if ($varType instanceof Nullable) {
|
||||
$nullable = true;
|
||||
$varType = $varType->getActualType();
|
||||
}
|
||||
|
||||
if (!$varType instanceof Compound) {
|
||||
if ($varType instanceof Null_) {
|
||||
$nullable = true;
|
||||
}
|
||||
|
||||
$type = $this->createType($varType, $nullable);
|
||||
if (null !== $type) {
|
||||
$types[] = $type;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
$varTypes = [];
|
||||
for ($typeIndex = 0; $varType->has($typeIndex); ++$typeIndex) {
|
||||
$type = $varType->get($typeIndex);
|
||||
|
||||
// If null is present, all types are nullable
|
||||
if ($type instanceof Null_) {
|
||||
$nullable = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type instanceof Nullable) {
|
||||
$nullable = true;
|
||||
$type = $type->getActualType();
|
||||
}
|
||||
|
||||
$varTypes[] = $type;
|
||||
}
|
||||
|
||||
foreach ($varTypes as $varType) {
|
||||
$type = $this->createType($varType, $nullable);
|
||||
if (null !== $type) {
|
||||
$types[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@see Type} from a PHPDoc type.
|
||||
*/
|
||||
private function createType(DocType $type, bool $nullable, string $docType = null): ?Type
|
||||
{
|
||||
$docType = $docType ?? (string) $type;
|
||||
|
||||
if ($type instanceof Collection) {
|
||||
$fqsen = $type->getFqsen();
|
||||
if ($fqsen && 'list' === $fqsen->getName() && !class_exists(List_::class, false) && !class_exists((string) $fqsen)) {
|
||||
// Workaround for phpdocumentor/type-resolver < 1.6
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), $this->getTypes($type->getValueType()));
|
||||
}
|
||||
|
||||
[$phpType, $class] = $this->getPhpTypeAndClass((string) $fqsen);
|
||||
|
||||
$key = $this->getTypes($type->getKeyType());
|
||||
$value = $this->getTypes($type->getValueType());
|
||||
|
||||
// More than 1 type returned means it is a Compound type, which is
|
||||
// not handled by Type, so better use a null value.
|
||||
$key = 1 === \count($key) ? $key[0] : null;
|
||||
$value = 1 === \count($value) ? $value[0] : null;
|
||||
|
||||
return new Type($phpType, $nullable, $class, true, $key, $value);
|
||||
}
|
||||
|
||||
// Cannot guess
|
||||
if (!$docType || 'mixed' === $docType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str_ends_with($docType, '[]')) {
|
||||
$collectionKeyType = new Type(Type::BUILTIN_TYPE_INT);
|
||||
$collectionValueType = $this->createType($type, false, substr($docType, 0, -2));
|
||||
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
|
||||
}
|
||||
|
||||
if ((str_starts_with($docType, 'list<') || str_starts_with($docType, 'array<')) && $type instanceof Array_) {
|
||||
// array<value> is converted to x[] which is handled above
|
||||
// so it's only necessary to handle array<key, value> here
|
||||
$collectionKeyType = $this->getTypes($type->getKeyType())[0];
|
||||
|
||||
$collectionValueTypes = $this->getTypes($type->getValueType());
|
||||
if (1 != \count($collectionValueTypes)) {
|
||||
// the Type class does not support union types yet, so assume that no type was defined
|
||||
$collectionValueType = null;
|
||||
} else {
|
||||
$collectionValueType = $collectionValueTypes[0];
|
||||
}
|
||||
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
|
||||
}
|
||||
|
||||
$docType = $this->normalizeType($docType);
|
||||
[$phpType, $class] = $this->getPhpTypeAndClass($docType);
|
||||
|
||||
if ('array' === $docType) {
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, null, null);
|
||||
}
|
||||
|
||||
return new Type($phpType, $nullable, $class);
|
||||
}
|
||||
|
||||
private function normalizeType(string $docType): string
|
||||
{
|
||||
switch ($docType) {
|
||||
case 'integer':
|
||||
return 'int';
|
||||
|
||||
case 'boolean':
|
||||
return 'bool';
|
||||
|
||||
// real is not part of the PHPDoc standard, so we ignore it
|
||||
case 'double':
|
||||
return 'float';
|
||||
|
||||
case 'callback':
|
||||
return 'callable';
|
||||
|
||||
case 'void':
|
||||
return 'null';
|
||||
|
||||
default:
|
||||
return $docType;
|
||||
}
|
||||
}
|
||||
|
||||
private function getPhpTypeAndClass(string $docType): array
|
||||
{
|
||||
if (\in_array($docType, Type::$builtinTypes)) {
|
||||
return [$docType, null];
|
||||
}
|
||||
|
||||
if (\in_array($docType, ['parent', 'self', 'static'], true)) {
|
||||
return ['object', $docType];
|
||||
}
|
||||
|
||||
return ['object', ltrim($docType, '\\')];
|
||||
}
|
||||
}
|
188
vendor/symfony/property-info/Util/PhpStanTypeHelper.php
vendored
Normal file
188
vendor/symfony/property-info/Util/PhpStanTypeHelper.php
vendored
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyInfo\Util;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
||||
use Symfony\Component\PropertyInfo\PhpStan\NameScope;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
/**
|
||||
* Transforms a php doc tag value to a {@link Type} instance.
|
||||
*
|
||||
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class PhpStanTypeHelper
|
||||
{
|
||||
/**
|
||||
* Creates a {@see Type} from a PhpDocTagValueNode type.
|
||||
*
|
||||
* @return Type[]
|
||||
*/
|
||||
public function getTypes(PhpDocTagValueNode $node, NameScope $nameScope): array
|
||||
{
|
||||
if ($node instanceof ParamTagValueNode || $node instanceof ReturnTagValueNode || $node instanceof VarTagValueNode) {
|
||||
return $this->compressNullableType($this->extractTypes($node->type, $nameScope));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Because PhpStan extract null as a separated type when Symfony / PHP compress it in the first available type we
|
||||
* need this method to mimic how Symfony want null types.
|
||||
*
|
||||
* @param Type[] $types
|
||||
*
|
||||
* @return Type[]
|
||||
*/
|
||||
private function compressNullableType(array $types): array
|
||||
{
|
||||
$firstTypeIndex = null;
|
||||
$nullableTypeIndex = null;
|
||||
|
||||
foreach ($types as $k => $type) {
|
||||
if (null === $firstTypeIndex && Type::BUILTIN_TYPE_NULL !== $type->getBuiltinType() && !$type->isNullable()) {
|
||||
$firstTypeIndex = $k;
|
||||
}
|
||||
|
||||
if (null === $nullableTypeIndex && Type::BUILTIN_TYPE_NULL === $type->getBuiltinType()) {
|
||||
$nullableTypeIndex = $k;
|
||||
}
|
||||
|
||||
if (null !== $firstTypeIndex && null !== $nullableTypeIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $firstTypeIndex && null !== $nullableTypeIndex) {
|
||||
$firstType = $types[$firstTypeIndex];
|
||||
$types[$firstTypeIndex] = new Type(
|
||||
$firstType->getBuiltinType(),
|
||||
true,
|
||||
$firstType->getClassName(),
|
||||
$firstType->isCollection(),
|
||||
$firstType->getCollectionKeyTypes(),
|
||||
$firstType->getCollectionValueTypes()
|
||||
);
|
||||
unset($types[$nullableTypeIndex]);
|
||||
}
|
||||
|
||||
return array_values($types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type[]
|
||||
*/
|
||||
private function extractTypes(TypeNode $node, NameScope $nameScope): array
|
||||
{
|
||||
if ($node instanceof UnionTypeNode) {
|
||||
$types = [];
|
||||
foreach ($node->types as $type) {
|
||||
if ($type instanceof ConstTypeNode) {
|
||||
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
|
||||
return [];
|
||||
}
|
||||
foreach ($this->extractTypes($type, $nameScope) as $subType) {
|
||||
$types[] = $subType;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->compressNullableType($types);
|
||||
}
|
||||
if ($node instanceof GenericTypeNode) {
|
||||
[$mainType] = $this->extractTypes($node->type, $nameScope);
|
||||
|
||||
$collectionKeyTypes = $mainType->getCollectionKeyTypes();
|
||||
$collectionKeyValues = [];
|
||||
if (1 === \count($node->genericTypes)) {
|
||||
foreach ($this->extractTypes($node->genericTypes[0], $nameScope) as $subType) {
|
||||
$collectionKeyValues[] = $subType;
|
||||
}
|
||||
} elseif (2 === \count($node->genericTypes)) {
|
||||
foreach ($this->extractTypes($node->genericTypes[0], $nameScope) as $keySubType) {
|
||||
$collectionKeyTypes[] = $keySubType;
|
||||
}
|
||||
foreach ($this->extractTypes($node->genericTypes[1], $nameScope) as $valueSubType) {
|
||||
$collectionKeyValues[] = $valueSubType;
|
||||
}
|
||||
}
|
||||
|
||||
return [new Type($mainType->getBuiltinType(), $mainType->isNullable(), $mainType->getClassName(), true, $collectionKeyTypes, $collectionKeyValues)];
|
||||
}
|
||||
if ($node instanceof ArrayShapeNode) {
|
||||
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)];
|
||||
}
|
||||
if ($node instanceof ArrayTypeNode) {
|
||||
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_INT)], $this->extractTypes($node->type, $nameScope))];
|
||||
}
|
||||
if ($node instanceof CallableTypeNode || $node instanceof CallableTypeParameterNode) {
|
||||
return [new Type(Type::BUILTIN_TYPE_CALLABLE)];
|
||||
}
|
||||
if ($node instanceof NullableTypeNode) {
|
||||
$subTypes = $this->extractTypes($node->type, $nameScope);
|
||||
if (\count($subTypes) > 1) {
|
||||
$subTypes[] = new Type(Type::BUILTIN_TYPE_NULL);
|
||||
|
||||
return $subTypes;
|
||||
}
|
||||
|
||||
return [new Type($subTypes[0]->getBuiltinType(), true, $subTypes[0]->getClassName(), $subTypes[0]->isCollection(), $subTypes[0]->getCollectionKeyTypes(), $subTypes[0]->getCollectionValueTypes())];
|
||||
}
|
||||
if ($node instanceof ThisTypeNode) {
|
||||
return [new Type(Type::BUILTIN_TYPE_OBJECT, false, $nameScope->resolveRootClass())];
|
||||
}
|
||||
if ($node instanceof IdentifierTypeNode) {
|
||||
if (\in_array($node->name, Type::$builtinTypes)) {
|
||||
return [new Type($node->name, false, null, \in_array($node->name, Type::$builtinCollectionTypes))];
|
||||
}
|
||||
|
||||
switch ($node->name) {
|
||||
case 'integer':
|
||||
return [new Type(Type::BUILTIN_TYPE_INT)];
|
||||
case 'list':
|
||||
case 'non-empty-list':
|
||||
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT))];
|
||||
case 'non-empty-array':
|
||||
return [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)];
|
||||
case 'mixed':
|
||||
return []; // mixed seems to be ignored in all other extractors
|
||||
case 'parent':
|
||||
return [new Type(Type::BUILTIN_TYPE_OBJECT, false, $node->name)];
|
||||
case 'static':
|
||||
case 'self':
|
||||
return [new Type(Type::BUILTIN_TYPE_OBJECT, false, $nameScope->resolveRootClass())];
|
||||
case 'void':
|
||||
return [new Type(Type::BUILTIN_TYPE_NULL)];
|
||||
}
|
||||
|
||||
return [new Type(Type::BUILTIN_TYPE_OBJECT, false, $nameScope->resolveStringName($node->name))];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user