/**
  * @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 = Utils::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);
 }
Beispiel #2
0
 /**
  * @todo Turn this into a class "FunctionEntityFactory"
  * @param \ReflectionParameter $reflection
  * @param array $docs
  * @return FunctionEntity
  */
 private function createParameterEntity(\ReflectionParameter $reflection, $docs)
 {
     // need to use slash instead of pipe or md-generation will get it wrong
     $def = false;
     $type = 'mixed';
     $declaredType = self::getParamType($reflection);
     if (!isset($docs['type'])) {
         $docs['type'] = '';
     }
     if ($declaredType && !($declaredType == 'array' && substr($docs['type'], -2) == '[]') && $declaredType != $docs['type']) {
         if ($declaredType && $docs['type']) {
             $posClassA = Utils::getClassBaseName($docs['type']);
             $posClassB = Utils::getClassBaseName($declaredType);
             if ($posClassA == $posClassB) {
                 $docs['type'] = $declaredType;
             } else {
                 $docs['type'] = empty($docs['type']) ? $declaredType : $docs['type'] . '/' . $declaredType;
             }
         } else {
             $docs['type'] = empty($docs['type']) ? $declaredType : $docs['type'] . '/' . $declaredType;
         }
     }
     try {
         $def = $reflection->getDefaultValue();
         $type = $this->getTypeFromVal($def);
         if (is_string($def)) {
             $def = "`'{$def}'`";
         } elseif (is_bool($def)) {
             $def = $def ? 'true' : 'false';
         } elseif (is_null($def)) {
             $def = 'null';
         } elseif (is_array($def)) {
             $def = 'array()';
         }
     } catch (\Exception $e) {
     }
     $varName = '$' . $reflection->getName();
     if (!empty($docs)) {
         $docs['default'] = $def;
         if ($type == 'mixed' && $def == 'null' && strpos($docs['type'], '\\') === 0) {
             $type = false;
         }
         if ($type && $def && !empty($docs['type']) && $docs['type'] != $type && strpos($docs['type'], '|') === false) {
             if (substr($docs['type'], strpos($docs['type'], '\\')) == substr($declaredType, strpos($declaredType, '\\'))) {
                 $docs['type'] = $declaredType;
             } else {
                 $docs['type'] = $type . '/' . $docs['type'];
             }
         } elseif ($type && empty($docs['type'])) {
             $docs['type'] = $type;
         }
     } else {
         $docs = ['descriptions' => '', 'name' => $varName, 'default' => $def, 'type' => $type];
     }
     $param = new ParamEntity();
     $param->setDescription(isset($docs['description']) ? $docs['description'] : '');
     $param->setName($varName);
     $param->setDefault($docs['default']);
     $param->setType(empty($docs['type']) ? 'mixed' : str_replace(['|', '\\\\'], ['/', '\\'], $docs['type']));
     return $param;
 }