|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Reflection\Native; |
| 4 | + |
| 5 | +use PHPStan\Reflection\ParameterReflectionWithPhpDocs; |
| 6 | +use PHPStan\Reflection\PassedByReference; |
| 7 | +use PHPStan\Type\ArrayType; |
| 8 | +use PHPStan\Type\IntegerType; |
| 9 | +use PHPStan\Type\Type; |
| 10 | + |
| 11 | +class NativeParameterWithPhpDocsReflection implements ParameterReflectionWithPhpDocs |
| 12 | +{ |
| 13 | + |
| 14 | + private string $name; |
| 15 | + |
| 16 | + private bool $optional; |
| 17 | + |
| 18 | + private \PHPStan\Type\Type $type; |
| 19 | + |
| 20 | + private \PHPStan\Type\Type $phpDocType; |
| 21 | + |
| 22 | + private \PHPStan\Type\Type $nativeType; |
| 23 | + |
| 24 | + private \PHPStan\Reflection\PassedByReference $passedByReference; |
| 25 | + |
| 26 | + private bool $variadic; |
| 27 | + |
| 28 | + private ?\PHPStan\Type\Type $defaultValue; |
| 29 | + |
| 30 | + private bool $variadicParameterAlreadyExpanded; |
| 31 | + |
| 32 | + public function __construct( |
| 33 | + string $name, |
| 34 | + bool $optional, |
| 35 | + Type $type, |
| 36 | + Type $phpDocType, |
| 37 | + Type $nativeType, |
| 38 | + PassedByReference $passedByReference, |
| 39 | + bool $variadic, |
| 40 | + ?Type $defaultValue, |
| 41 | + bool $variadicParameterAlreadyExpanded = false |
| 42 | + ) |
| 43 | + { |
| 44 | + $this->name = $name; |
| 45 | + $this->optional = $optional; |
| 46 | + $this->type = $type; |
| 47 | + $this->phpDocType = $phpDocType; |
| 48 | + $this->nativeType = $nativeType; |
| 49 | + $this->passedByReference = $passedByReference; |
| 50 | + $this->variadic = $variadic; |
| 51 | + $this->defaultValue = $defaultValue; |
| 52 | + $this->variadicParameterAlreadyExpanded = $variadicParameterAlreadyExpanded; |
| 53 | + } |
| 54 | + |
| 55 | + public function getName(): string |
| 56 | + { |
| 57 | + return $this->name; |
| 58 | + } |
| 59 | + |
| 60 | + public function isOptional(): bool |
| 61 | + { |
| 62 | + return $this->optional; |
| 63 | + } |
| 64 | + |
| 65 | + public function getType(): Type |
| 66 | + { |
| 67 | + $type = $this->type; |
| 68 | + if ($this->variadic && !$this->variadicParameterAlreadyExpanded) { |
| 69 | + $type = new ArrayType(new IntegerType(), $type); |
| 70 | + } |
| 71 | + |
| 72 | + return $type; |
| 73 | + } |
| 74 | + |
| 75 | + public function getPhpDocType(): Type |
| 76 | + { |
| 77 | + return $this->phpDocType; |
| 78 | + } |
| 79 | + |
| 80 | + public function getNativeType(): Type |
| 81 | + { |
| 82 | + return $this->nativeType; |
| 83 | + } |
| 84 | + |
| 85 | + public function passedByReference(): PassedByReference |
| 86 | + { |
| 87 | + return $this->passedByReference; |
| 88 | + } |
| 89 | + |
| 90 | + public function isVariadic(): bool |
| 91 | + { |
| 92 | + return $this->variadic; |
| 93 | + } |
| 94 | + |
| 95 | + public function getDefaultValue(): ?Type |
| 96 | + { |
| 97 | + return $this->defaultValue; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @param mixed[] $properties |
| 102 | + * @return self |
| 103 | + */ |
| 104 | + public static function __set_state(array $properties): self |
| 105 | + { |
| 106 | + return new self( |
| 107 | + $properties['name'], |
| 108 | + $properties['optional'], |
| 109 | + $properties['type'], |
| 110 | + $properties['phpDocType'], |
| 111 | + $properties['nativeType'], |
| 112 | + $properties['passedByReference'], |
| 113 | + $properties['variadic'], |
| 114 | + $properties['defaultValue'] |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | +} |
0 commit comments