Вход Регистрация
Файл: vendor/nikic/php-parser/lib/PhpParser/Builder/Param.php
Строк: 84
<?php declare(strict_types=1);

namespace 
PhpParserBuilder;

use 
PhpParser;
use 
PhpParserBuilderHelpers;
use 
PhpParserNode;

class 
Param implements PhpParserBuilder
{
    protected 
$name;

    protected 
$default = null;

    
/** @var NodeIdentifier|NodeName|NodeNullableType|null */
    
protected $type = null;

    protected 
$byRef = false;

    protected 
$variadic = false;

    
/** @var NodeAttributeGroup[] */
    
protected $attributeGroups = [];

    
/**
     * Creates a parameter builder.
     *
     * @param string $name Name of the parameter
     */
    
public function __construct(string $name) {
        
$this->name = $name;
    }

    
/**
     * Sets default value for the parameter.
     *
     * @param mixed $value Default value to use
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function setDefault($value) {
        
$this->default = BuilderHelpers::normalizeValue($value);

        return 
$this;
    }

    
/**
     * Sets type for the parameter.
     *
     * @param string|NodeName|NodeIdentifier|NodeComplexType $type Parameter type
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function setType($type) {
        
$this->type = BuilderHelpers::normalizeType($type);
        if (
$this->type == 'void') {
            throw new 
LogicException('Parameter type cannot be void');
        }

        return 
$this;
    }

    
/**
     * Sets type for the parameter.
     *
     * @param string|NodeName|NodeIdentifier|NodeComplexType $type Parameter type
     *
     * @return $this The builder instance (for fluid interface)
     *
     * @deprecated Use setType() instead
     */
    
public function setTypeHint($type) {
        return 
$this->setType($type);
    }

    
/**
     * Make the parameter accept the value by reference.
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function makeByRef() {
        
$this->byRef = true;

        return 
$this;
    }

    
/**
     * Make the parameter variadic
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function makeVariadic() {
        
$this->variadic = true;

        return 
$this;
    }

    
/**
     * Adds an attribute group.
     *
     * @param NodeAttribute|NodeAttributeGroup $attribute
     *
     * @return $this The builder instance (for fluid interface)
     */
    
public function addAttribute($attribute) {
        
$this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute);

        return 
$this;
    }

    
/**
     * Returns the built parameter node.
     *
     * @return NodeParam The built parameter node
     */
    
public function getNode() : Node {
        return new 
NodeParam(
            new 
NodeExprVariable($this->name),
            
$this->default, $this->type, $this->byRef, $this->variadic, [], 0, $this->attributeGroups
        
);
    }
}
Онлайн: 0
Реклама