You are here

public function Collection::add in Zircon Profile 8

Same name in this branch
  1. 8 vendor/doctrine/collections/lib/Doctrine/Common/Collections/Collection.php \Doctrine\Common\Collections\Collection::add()
  2. 8 vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Type/Collection.php \phpDocumentor\Reflection\DocBlock\Type\Collection::add()
Same name and namespace in other branches
  1. 8.0 vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Type/Collection.php \phpDocumentor\Reflection\DocBlock\Type\Collection::add()

Adds a new type to the collection and expands it if it contains a relative namespace.

If a class in the type contains a relative namespace than this collection will try to expand that into a FQCN.

Parameters

string $type A 'Type' as defined in the phpDocumentor: documentation.

Return value

void

Throws

\InvalidArgumentException if a non-string argument is passed.

definition of a type.

See also

http://phpdoc.org/docs/latest/for-users/types.html for the

1 call to Collection::add()
Collection::__construct in vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Type/Collection.php
Registers the namespace and aliases; uses that to add and expand the given types.

File

vendor/phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Type/Collection.php, line 99

Class

Collection
Collection

Namespace

phpDocumentor\Reflection\DocBlock\Type

Code

public function add($type) {
  if (!is_string($type)) {
    throw new \InvalidArgumentException('A type should be represented by a string, received: ' . var_export($type, true));
  }

  // separate the type by the OR operator
  $type_parts = explode(self::OPERATOR_OR, $type);
  foreach ($type_parts as $part) {
    $expanded_type = $this
      ->expand($part);
    if ($expanded_type) {
      $this[] = $expanded_type;
    }
  }
}