Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice when using array as default value for parameter #18

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment
Closed

Notice when using array as default value for parameter #18

weierophinney opened this issue Dec 31, 2019 · 1 comment
Assignees
Labels
Bug Something isn't working Won't Fix This will not be worked on
Milestone

Comments

@weierophinney
Copy link
Member

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.


Originally posted by @4orever at zendframework/zend-code#88

@Ocramius
Copy link
Member

No longer needed as per #58

@Ocramius Ocramius added Bug Something isn't working Won't Fix This will not be worked on labels Nov 30, 2020
@Ocramius Ocramius self-assigned this Nov 30, 2020
@Ocramius Ocramius added this to the 4.0.0 milestone Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Won't Fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants