visibility = $visibility; } /** @psalm-return non-empty-string */ public function generate(): string { return $this->visibility . ' ' . parent::generate(); } public static function fromReflection(ParameterReflection $reflectionParameter): self { if (! $reflectionParameter->isPromoted()) { throw new RuntimeException( sprintf('Can not create "%s" from unprompted reflection.', self::class) ); } $visibility = self::VISIBILITY_PUBLIC; if ($reflectionParameter->isProtectedPromoted()) { $visibility = self::VISIBILITY_PROTECTED; } elseif ($reflectionParameter->isPrivatePromoted()) { $visibility = self::VISIBILITY_PRIVATE; } return self::fromParameterGeneratorWithVisibility( parent::fromReflection($reflectionParameter), $visibility ); } /** @psalm-param PromotedParameterGenerator::VISIBILITY_* $visibility */ public static function fromParameterGeneratorWithVisibility(ParameterGenerator $generator, string $visibility): self { $name = $generator->getName(); $type = $generator->getType(); if ('' === $name) { throw new \Laminas\Code\Generator\Exception\RuntimeException( 'Name of promoted parameter must be non-empty-string.' ); } if ('' === $type) { throw new \Laminas\Code\Generator\Exception\RuntimeException( 'Type of promoted parameter must be non-empty-string.' ); } return new self( $name, $type, $visibility, $generator->getPosition(), $generator->getPassedByReference() ); } }