zendframework / zend-code

BSD 3-Clause "New" or "Revised" License
1.68k stars 78 forks source link

Notice when using array as default value for parameter #88

Open 4orever opened 8 years ago

4orever commented 8 years ago

I'm trying to set array for default value:

public function exportCategory($sourceId, $targetParentId, $params = [1, 2, 3])

And getting notice:

Notice: Undefined index: type in /home/forever/prj/Enterum/vendor/zendframework/zend-code/src/Scanner/MethodScanner.php on line 322

25  0.2380  7434808 KJSencha\Direct\Remoting\Api\Factory\ApiBuilder->buildAction( ) .../ApiBuilder.php:138
26  0.2551  7955224 KJSencha\Direct\Remoting\Api\Factory\ApiBuilder->buildMethod( ) .../ApiBuilder.php:162
27  0.2551  7955352 Zend\Code\Scanner\MethodScanner->getNumberOfParameters( )   .../ApiBuilder.php:178
28  0.2551  7955352 Zend\Code\Scanner\MethodScanner->getParameters( )   .../MethodScanner.php:308

Below is a piece of ApiBuilder.php:

/**
 * Builds and populates Action object based on the provided class name
 *
 * @param  string $className
 * @return Action
 */
public function buildAction($className)
{
    $classReflection = new ClassReflection($className);
    $scanner = new FileScanner($classReflection->getFileName(), $this->annotationManager);
    $classScanner = $scanner->getClass($classReflection->getName());
    $action = new Action($classScanner->getName());

    foreach ($classScanner->getMethods() as $classMethod) {
        if ($classMethod->isPublic() && $classMethod->getName() != '__construct') {
            $action->addMethod($this->buildMethod($classMethod));
        }
    }

    return $action;
}

/**
 * Builds a method object based on the provided method scanner
 *
 * @param  MethodScanner $classMethod
 * @return Method
 */
protected function buildMethod(MethodScanner $classMethod)
{
    $method = new Method($classMethod->getName());
    $method->setNumberOfParameters($classMethod->getNumberOfParameters());

    // Loop through annotations
    if ($annotations = $classMethod->getAnnotations($this->annotationManager)) {
        foreach ($annotations as $annotation) {
            // @todo annotations should implement some kind of interface?
            if (method_exists($annotation, 'decorateObject')) {
                $annotation->decorateObject($method);
            }
        }
    }

    return $method;
}

With $params = [1,2], for example, notice disapears.

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at https://github.com/laminas/laminas-code/issues/18.