Пример #1
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::stringNotEmpty($body);
     Assert::allNotNull([$typeResolver, $descriptionFactory]);
     $parts = preg_split('/(\\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
     $type = null;
     $variableName = '';
     $isVariadic = false;
     // if the first item that is encountered is not a variable; it is a type
     if (isset($parts[0]) && strlen($parts[0]) > 0 && $parts[0][0] !== '$') {
         $type = $typeResolver->resolve(array_shift($parts), $context);
         array_shift($parts);
     }
     // if the next item starts with a $ or ...$ it must be the variable name
     if (isset($parts[0]) && strlen($parts[0]) > 0 && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) {
         $variableName = array_shift($parts);
         array_shift($parts);
         if (substr($variableName, 0, 3) === '...') {
             $isVariadic = true;
             $variableName = substr($variableName, 3);
         }
         if (substr($variableName, 0, 1) === '$') {
             $variableName = substr($variableName, 1);
         }
     }
     $description = $descriptionFactory->create(implode('', $parts), $context);
     return new static($variableName, $type, $isVariadic, $description);
 }
Пример #2
0
 /**
  * Creates a new tag that represents any unknown tag type.
  *
  * @param string             $body
  * @param string             $name
  * @param DescriptionFactory $descriptionFactory
  * @param Context            $context
  *
  * @return static
  */
 public static function create($body, $name = '', DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::string($body);
     Assert::stringNotEmpty($name);
     $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
     return new static($name, $description);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, FqsenResolver $resolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::string($body);
     Assert::allNotNull([$resolver, $descriptionFactory]);
     $parts = preg_split('/\\s+/Su', $body, 2);
     return new static($resolver->resolve($parts[0], $context), $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context));
 }
Пример #4
0
 /**
  * @return static
  */
 public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::nullOrString($body);
     if (empty($body)) {
         return new static();
     }
     $matches = [];
     if (!preg_match('/^(' . self::REGEX_VECTOR . ')\\s*(.+)?$/sux', $body, $matches)) {
         return null;
     }
     return new static($matches[1], $descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context));
 }
Пример #5
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $field = null;
     $group = null;
     $type = null;
     $size = null;
     $optional = null;
     $default_value = null;
     $description = null;
     //Is the first part our group?
     if (preg_match('/^\\([^)]*\\)/', $body) !== 0) {
         $parts = preg_split('/\\)\\s*/', $body, 2);
         $group = substr($parts[0], 1);
         $body = $parts[1];
     }
     $parts = preg_split('/(\\s+)/Su', $body, null, PREG_SPLIT_DELIM_CAPTURE);
     //Is the first part our type?
     if (preg_match('/{([^{]+)(?:{([^}]+)})?}/', $parts[0], $matches) !== 0) {
         array_shift($parts);
         array_shift($parts);
         if (!empty($matches[1])) {
             $type = $matches[1];
         } else {
             $type = null;
         }
         if (!empty($matches[2])) {
             $size = $matches[2];
         } else {
             $size = null;
         }
     }
     $field = array_shift($parts);
     array_shift($parts);
     if (strpos($field, '?') === 0) {
         $optional = true;
         $field = substr($field, 1);
     } else {
         $optional = false;
     }
     if (strpos($field, '=') !== false) {
         list($field, $default_value) = preg_split('/=/', $field, 2);
     } else {
         $default_value = null;
     }
     $description = $description_factory->create(implode('', $parts), $context);
     return new static($field, $group, $type, $size, $optional, $default_value, $description);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::stringNotEmpty($body);
     Assert::allNotNull([$typeResolver, $descriptionFactory]);
     // 1. none or more whitespace
     // 2. optionally the keyword "static" followed by whitespace
     // 3. optionally a word with underscores followed by whitespace : as
     //    type for the return value
     // 4. then optionally a word with underscores followed by () and
     //    whitespace : as method name as used by phpDocumentor
     // 5. then a word with underscores, followed by ( and any character
     //    until a ) and whitespace : as method name with signature
     // 6. any remaining text : as description
     if (!preg_match('/^
             # Static keyword
             # Declares a static method ONLY if type is also present
             (?:
                 (static)
                 \\s+
             )?
             # Return type
             (?:
                 ([\\w\\|_\\\\]+)
                 \\s+
             )?
             # Legacy method name (not captured)
             (?:
                 [\\w_]+\\(\\)\\s+
             )?
             # Method name
             ([\\w\\|_\\\\]+)
             # Arguments
             \\(([^\\)]*)\\)
             \\s*
             # Description
             (.*)
         $/sux', $body, $matches)) {
         return null;
     }
     list(, $static, $returnType, $methodName, $arguments, $description) = $matches;
     $static = $static === 'static';
     $returnType = $typeResolver->resolve($returnType, $context);
     $description = $descriptionFactory->create($description, $context);
     $arguments = explode(',', $arguments);
     foreach ($arguments as &$argument) {
         $argument = explode(' ', trim($argument));
         if ($argument[0][0] === '$') {
             $argumentName = substr($argument[0], 1);
             $argumentType = new Void();
         } else {
             $argumentType = $typeResolver->resolve($argument[0], $context);
             $argumentName = '';
             if (isset($argument[1])) {
                 $argumentName = substr($argument[1], 1);
             }
         }
         $argument = ['name' => $argumentName, 'type' => $argumentType];
     }
     return new static($methodName, $arguments, $returnType, $static, $description);
 }
 /**
  * @param object|string $docblock A string containing the DocBlock to parse or an object supporting the
  *                                getDocComment method (such as a ReflectionClass object).
  * @param Types\Context $context
  * @param Location      $location
  *
  * @return DocBlock
  */
 public function create($docblock, Types\Context $context = null, Location $location = null)
 {
     if (is_object($docblock)) {
         if (!method_exists($docblock, 'getDocComment')) {
             $exceptionMessage = 'Invalid object passed; the given object must support the getDocComment method';
             throw new \InvalidArgumentException($exceptionMessage);
         }
         $docblock = $docblock->getDocComment();
     }
     Assert::stringNotEmpty($docblock);
     if ($context === null) {
         $context = new Context('');
     }
     $parts = $this->splitDocBlock($this->stripDocComment($docblock));
     list($templateMarker, $summary, $description, $tags) = $parts;
     return new DocBlock($summary, $description ? $this->descriptionFactory->create($description, $context) : null, $this->parseTagBlock($tags), $context, $location, $templateMarker === '#@+', $templateMarker === '#@-');
 }
Пример #8
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $parts = preg_split('/(\\s+)/Su', $body, 3);
     if (!empty($parts[0])) {
         $var = array_shift($parts);
     }
     if (!empty($parts[0])) {
         $type = array_shift($parts);
     }
     if (!empty($parts[0])) {
         $description = $description_factory->create($parts[0], $context);
     } else {
         $description = null;
     }
     return new static($var, $type, $size, $description);
 }
Пример #9
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $field = null;
     $group = null;
     $type = null;
     $description = null;
     $parts = preg_split('/(\\s+)/Su', $body, 4, PREG_SPLIT_DELIM_CAPTURE);
     //Is the first part our group?
     if (preg_match('/\\([^)]+\\)/', $parts[0]) !== 0) {
         $group = substr(array_shift($parts), 1, -1);
         array_shift($parts);
     }
     //Is the first part our type?
     if (preg_match('/\\{[^}]+\\}/', $parts[0]) !== 0) {
         $type = substr(array_shift($parts), 1, -1);
         array_shift($parts);
     }
     $field = array_shift($parts);
     array_shift($parts);
     $description = $description_factory->create(implode('', $parts), $context);
     return new static($field, $group, $type, $description);
 }
    /**
     * @covers ::__construct
     * @covers ::create
     * @uses   phpDocumentor\Reflection\DocBlock\Description
     */
    public function testIfSuperfluousStartingSpacesAreRemoved()
    {
        $factory = new DescriptionFactory(m::mock(TagFactory::class));
        $descriptionText = <<<DESCRIPTION
This is a multiline
  description that you commonly
  see with tags.

      It does have a multiline code sample
      that should align, no matter what

  All spaces superfluous spaces on the
  second and later lines should be
  removed but the code sample should
  still be indented.
DESCRIPTION;
        $expectedDescription = <<<DESCRIPTION
This is a multiline
description that you commonly
see with tags.

    It does have a multiline code sample
    that should align, no matter what

All spaces superfluous spaces on the
second and later lines should be
removed but the code sample should
still be indented.
DESCRIPTION;
        $description = $factory->create($descriptionText, new Context(''));
        $this->assertSame($expectedDescription, $description->render());
    }
Пример #11
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $description = $description_factory->create($body, $context);
     return new static($description);
 }