function testParams()
 {
     $paramA = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 2);
     $paramB = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 3);
     $paramC = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 0);
     $typeA = \PHPDocsMD\Reflector::getParamType($paramA);
     $typeB = \PHPDocsMD\Reflector::getParamType($paramB);
     $typeC = \PHPDocsMD\Reflector::getParamType($paramC);
     $this->assertEmpty($typeC);
     $this->assertEquals('\\stdClass', $typeB);
     $this->assertEquals('\\Acme\\ExampleInterface', $typeA);
     $functions = $this->class->getFunctions();
     $params = $functions[2]->getParams();
     $this->assertTrue($functions[2]->hasParams());
     $this->assertFalse($functions[5]->hasParams());
     $this->assertEquals(4, count($params));
     $this->assertEquals(false, $params[0]->getDefault());
     $this->assertEquals('$arg', $params[0]->getName());
     $this->assertEquals('mixed', $params[0]->getType());
     $this->assertEquals('array()', $params[1]->getDefault());
     $this->assertEquals('$arr', $params[1]->getName());
     $this->assertEquals('array', $params[1]->getType());
     $this->assertEquals('null', $params[2]->getDefault());
     $this->assertEquals('$depr', $params[2]->getName());
     $this->assertEquals('\\Acme\\ExampleInterface', $params[2]->getType());
 }
 /**
  * @param $file
  * @return array
  */
 private function findClassInFile($file)
 {
     $ns = '';
     $class = false;
     foreach (explode(PHP_EOL, file_get_contents($file)) as $line) {
         if (strpos($line, '*') === false) {
             if (strpos($line, 'namespace') !== false) {
                 $ns = trim(current(array_slice(explode('namespace', $line), 1)), '; ');
                 $ns = ClassEntity::sanitizeClassName($ns);
             } elseif (strpos($line, 'class') !== false) {
                 $class = $this->extractClassNameFromLine('class', $line);
                 break;
             } elseif (strpos($line, 'interface') !== false) {
                 $class = $this->extractClassNameFromLine('interface', $line);
                 break;
             }
         }
     }
     return $class ? array($ns, $ns . '\\' . $class) : array(false, false);
 }
Ejemplo n.º 3
0
 /**
  * @param FunctionEntity $func
  * @param ClassEntity $class
  * @return FunctionEntity
  */
 private function findInheritedFunctionDeclaration(FunctionEntity $func, ClassEntity $class)
 {
     $funcName = $func->getName();
     $inheritedFuncDeclaration = $this->functionFinder->find($funcName, $class->getExtends());
     if (!$inheritedFuncDeclaration) {
         $inheritedFuncDeclaration = $this->functionFinder->findInClasses($funcName, $class->getInterfaces());
         if (!$inheritedFuncDeclaration) {
             throw new \RuntimeException('Function ' . $funcName . ' tries to inherit docs but no parent method is found');
         }
     }
     if (!$func->isAbstract() && !$class->isAbstract() && $inheritedFuncDeclaration->isAbstract()) {
         $inheritedFuncDeclaration->isAbstract(false);
     }
     return $inheritedFuncDeclaration;
 }