Added generics to Context (#22)

This commit is contained in:
Nereo Berardozzi
2024-12-24 19:06:41 +01:00
committed by GitHub
parent e5c8b970d6
commit 476f62b577
3 changed files with 33 additions and 4 deletions
+30 -2
View File
@@ -29,7 +29,10 @@ class Context
/** @var string Name of the structural element, within the namespace. */
protected $lsen = '';
/** @var string[] List of generics */
protected $generics = array();
/**
* Cteates a new context.
* @param string $namespace The namespace where this DocBlock
@@ -42,13 +45,15 @@ class Context
public function __construct(
$namespace = '',
array $namespace_aliases = array(),
$lsen = ''
$lsen = '',
array $generics = array()
) {
if (!empty($namespace)) {
$this->setNamespace($namespace);
}
$this->setNamespaceAliases($namespace_aliases);
$this->setLSEN($lsen);
$this->setGenerics($generics);
}
/**
@@ -76,6 +81,16 @@ class Context
{
return $this->lsen;
}
/**
* Returns the list of generics.
*
* @return string[] List of generics
*/
public function getGenerics()
{
return $this->generics;
}
/**
* Sets a new namespace.
@@ -151,4 +166,17 @@ class Context
$this->lsen = (string)$lsen;
return $this;
}
/**
* Sets a new list of generics.
*
* @param string[] $generics The new list of generics.
*
* @return $this
*/
public function setGenerics(array $generics)
{
$this->generics = $generics;
return $this;
}
}
@@ -78,7 +78,7 @@ class Collection extends \ArrayObject
array $generics = array()
) {
$this->context = null === $context ? new Context() : $context;
$this->generics = $generics;
$this->generics = array_merge($this->context->getGenerics(), $generics);
foreach ($types as $type) {
$this->add($type);
@@ -157,7 +157,7 @@ class CollectionTest extends TestCase
{
$collection = new Collection(
array(),
new Context('\My\Space', array('Alias' => '\My\Space\Aliasing')),
new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'), '', array('TParent')),
array('TValue')
);
$collection->add($fixture);
@@ -344,6 +344,7 @@ class CollectionTest extends TestCase
array('TValue', array('TValue')),
array('TValue[]', array('TValue[]')),
array('TValue|DocBlock', array('TValue', $namespace . 'DocBlock')),
array('TParent', array('TParent')),
);
}
}