setName() public method

public setName ( $name )
$name
        /**
         * @param AbstractVariableObject     $variable
         * @param \PhpParser\Node\Expr       $default
         * @return string
         */
        private function setVariableDefaultValue(AbstractVariableObject $variable, \PhpParser\Node\Expr $default = NULL) {
            if ($default === NULL) {
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\String) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('string');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\LNumber ||
                $default instanceof \PhpParser\Node\Expr\UnaryMinus ||
                $default instanceof \PhpParser\Node\Expr\UnaryPlus) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('integer');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\DNumber) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('float');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\Array_) {
                //var_dump($default);
                //$parameter->setDefault(join('\\', $default->items));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('array');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\ClassConstFetch) {
                $variable->setDefault(join('\\', $default->class->parts) . '::' . $default->name);
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\ConstFetch) {
                $variable->setDefault(join('\\', $default->name->parts));
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Trait_) {
                $variable->setName('__TRAIT__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Class_) {
                $variable->setDefault('__CLASS__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Method) {
                $variable->setName('__METHOD__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Dir) {
                $variable->setName('__DIR__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\File) {
                $variable->setName('__FILE__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Function_) {
                $variable->setName('__FUNC__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Line) {
                $variable->setName('__LINE__');
                return;
            }

            $type = get_class($default);
            $line = $default->startLine;
            $file = $this->result->getFileName();
            throw new ParseErrorException("Unexpected expression type '$type' for default value in line $line of file '$file'", ParseErrorException::UnexpectedExpr);
        }
Example #2
0
 /**
  * @param AbstractVariableObject     $variable
  * @param \PHPParser_Node_Expr       $default
  * @return string
  */
 private function setVariableDefaultValue(AbstractVariableObject $variable, \PHPParser_Node_Expr $default = NULL)
 {
     if ($default === NULL) {
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_String) {
         $variable->setDefault($default->getAttribute('originalValue'));
         if ($variable->getType() == '{unknown}') {
             $variable->setType('string');
         }
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_LNumber || $default instanceof \PHPParser_Node_Expr_UnaryMinus || $default instanceof \PHPParser_Node_Expr_UnaryPlus) {
         $variable->setDefault($default->getAttribute('originalValue'));
         if ($variable->getType() == '{unknown}') {
             $variable->setType('integer');
         }
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_DNumber) {
         $variable->setDefault($default->getAttribute('originalValue'));
         if ($variable->getType() == '{unknown}') {
             $variable->setType('float');
         }
         return;
     }
     if ($default instanceof \PHPParser_Node_Expr_Array) {
         //var_dump($default);
         //$parameter->setDefault(join('\\', $default->items));
         if ($variable->getType() == '{unknown}') {
             $variable->setType('array');
         }
         return;
     }
     if ($default instanceof \PHPParser_Node_Expr_ClassConstFetch) {
         $variable->setDefault(join('\\', $default->class->parts) . '::' . $default->name);
         return;
     }
     if ($default instanceof \PHPParser_Node_Expr_ConstFetch) {
         $variable->setDefault(join('\\', $default->name->parts));
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_TraitConst) {
         $variable->setName('__TRAIT__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_ClassConst) {
         $variable->setDefault('__CLASS__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_MethodConst) {
         $variable->setName('__METHOD__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_DirConst) {
         $variable->setName('__DIR__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_FileConst) {
         $variable->setName('__FILE__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_FuncConst) {
         $variable->setName('__FUNC__');
         return;
     }
     if ($default instanceof \PHPParser_Node_Scalar_LineConst) {
         $variable->setName('__LINE__');
         return;
     }
     $type = get_class($default);
     $line = $default->startLine;
     $file = $this->result->getFileName();
     throw new ParseErrorException("Unexpected expression type '{$type}' for default value in line {$line} of file '{$file}'", ParseErrorException::UnexpectedExpr);
 }