/** * @test */ public function it_should_parse_params_with_no_type() { $comment = '/** * @param string $name * @param $__attrs * @param $__content string|null * @return string */'; $vars = DocComments::getParameters($comment); $this->assertEquals(['name' => 'string', '__attrs' => null, '__content' => ['string', 'null']], $vars); }
/** * Initialize parameters array with reflection info. * Detect if there is $__content parameter -> is container * Detect if there is $__attrs parameter -> allow extra attributes */ protected function initialize() { $reflectionClass = new \ReflectionClass($this->class); $reflectionMethod = $reflectionClass->getMethod($this->method); $vars = DocComments::getParameters($reflectionMethod->getDocComment()); $this->parameters = []; $this->methodParameters = []; foreach ($reflectionMethod->getParameters() as $param) { $name = $param->getName(); $this->methodParameters[$name] = $param_def = new ComponentParameterDefinition($name, $this->guessParameterType($param, isset($vars[$name]) ? $vars[$name] : null) ?: 'mixed', $param->isDefaultValueAvailable(), $param->getDefaultValue()); if ($name === '__attrs') { $this->allowExtraParams = true; } elseif ($name === '__content') { $this->isContainer = true; } else { $this->parameters[$name] = $param_def; } } }