public function testCallableTypeHint()
 {
     if (PHP_VERSION_ID < 50400) {
         $this->markTestSkipped('`callable` is only supported in PHP >=5.4.0');
     }
     $parameter = new Reflection\ParameterReflection(array('ZendTest\\Code\\Reflection\\TestAsset\\CallableTypeHintClass', 'foo'), 'bar');
     $this->assertEquals('callable', $parameter->getType());
 }
Пример #2
0
 /**
  * Check if parameter is an array.
  *
  * @param ParameterReflection $param
  * @return bool
  */
 protected function _isArrayParam($param)
 {
     $isArray = $param->isArray();
     $docBlock = $param->getDeclaringFunction()->getDocBlock();
     /** If array type is not set explicitly in the method interface, examine annotations */
     if (!$isArray && $docBlock) {
         /** This pattern will help to skip parameters declarations which precede to the current one */
         $precedingParamsPattern = str_repeat('.*\\@param.*', $param->getPosition());
         $paramType = str_replace('\\', '\\\\', $param->getType());
         if (preg_match("/.*{$precedingParamsPattern}\\@param\\s+({$paramType}\\[\\]).*/is", $docBlock->getContents())) {
             $isArray = true;
         }
     }
     return $isArray;
 }
Пример #3
0
 /**
  * @dataProvider paramTypeTestProvider
  */
 public function testTypeReturn($param, $type)
 {
     $parameter = new Reflection\ParameterReflection(array('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass5', 'doSomething'), $param);
     $this->assertEquals($type, $parameter->getType());
 }
Пример #4
0
 /**
  * Get the parameter type
  *
  * @param ParameterReflection $param
  * @return string
  * @throws \LogicException
  */
 public function getParamType(ParameterReflection $param)
 {
     $type = $param->getType();
     if ($param->getType() == 'null') {
         throw new \LogicException(sprintf('@param annotation is incorrect for the parameter "%s" in the method "%s:%s".' . ' First declared type should not be null. E.g. string|null', $param->getName(), $param->getDeclaringClass()->getName(), $param->getDeclaringFunction()->name));
     }
     if ($type == 'array') {
         // try to determine class, if it's array of objects
         $docBlock = $param->getDeclaringFunction()->getDocBlock();
         $pattern = "/\\@param\\s+([\\w\\\\_]+\\[\\])\\s+\\\${$param->getName()}\n/";
         $matches = [];
         if (preg_match($pattern, $docBlock->getContents(), $matches)) {
             return $matches[1];
         }
         return "{$type}[]";
     }
     return $type;
 }
Пример #5
0
 /**
  * Get the parameter type
  *
  * @param ParameterReflection $param
  * @return string
  */
 public function getParamType(ParameterReflection $param)
 {
     $type = $param->getType();
     if ($type == 'array') {
         // try to determine class, if it's array of objects
         $docBlock = $param->getDeclaringFunction()->getDocBlock();
         $pattern = "/\\@param\\s+([\\w\\\\_]+\\[\\])\\s+\\\${$param->getName()}\n/";
         if (preg_match($pattern, $docBlock->getContents(), $matches)) {
             return $matches[1];
         }
         return "{$type}[]";
     }
     return $type;
 }