Skip to content

Commit e6a969a

Browse files
committed
Merge pull request #67 from mbed67/fix-bug-in-collection
fix for bug #1672 in phpDocumentor2
2 parents d68dbdc + 708c2c9 commit e6a969a

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/phpDocumentor/Reflection/DocBlock/Type/Collection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,21 @@ protected function expand($type)
161161
$namespace_aliases = $this->context->getNamespaceAliases();
162162
// if the first segment is not an alias; prepend namespace name and
163163
// return
164-
if (!isset($namespace_aliases[$type_parts[0]])) {
164+
if (!isset($namespace_aliases[$type_parts[0]]) &&
165+
!isset($namespace_aliases[strstr($type_parts[0], '::', true)])) {
165166
$namespace = $this->context->getNamespace();
166167
if ('' !== $namespace) {
167168
$namespace .= self::OPERATOR_NAMESPACE;
168169
}
169170
return self::OPERATOR_NAMESPACE . $namespace . $type;
170171
}
171172

173+
if (strpos($type_parts[0], '::')) {
174+
$type_parts[] = strstr($type_parts[0], '::');
175+
$type_parts[0] = $namespace_aliases[strstr($type_parts[0], '::', true)];
176+
return implode('', $type_parts);
177+
}
178+
172179
$type_parts[0] = $namespace_aliases[$type_parts[0]];
173180
$type = implode(self::OPERATOR_NAMESPACE, $type_parts);
174181
}

tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ public function testAddWithoutNamespace($fixture, $expected)
123123
$this->assertSame($expected, $collection->getArrayCopy());
124124
}
125125

126+
/**
127+
* @param string $fixture
128+
* @param array $expected
129+
*
130+
* @dataProvider provideTypesToExpandWithPropertyOrMethod
131+
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
132+
*
133+
* @return void
134+
*/
135+
public function testAddMethodsAndProperties($fixture, $expected)
136+
{
137+
$collection = new Collection(
138+
array(),
139+
new Context(null, array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'))
140+
);
141+
$collection->add($fixture);
142+
143+
$this->assertSame($expected, $collection->getArrayCopy());
144+
}
145+
126146
/**
127147
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
128148
* @expectedException InvalidArgumentException
@@ -177,6 +197,14 @@ public function provideTypesToExpand($method, $namespace = '\My\Space\\')
177197
'DocBlock[]|int[]',
178198
array($namespace.'DocBlock[]', 'int[]')
179199
),
200+
array(
201+
'LinkDescriptor::setLink()',
202+
array($namespace.'LinkDescriptor::setLink()')
203+
),
204+
array(
205+
'Alias\LinkDescriptor::setLink()',
206+
array('\My\Space\Aliasing\LinkDescriptor::setLink()')
207+
),
180208
);
181209
}
182210

@@ -192,4 +220,34 @@ public function provideTypesToExpandWithoutNamespace($method)
192220
{
193221
return $this->provideTypesToExpand($method, '\\');
194222
}
223+
224+
/**
225+
* Returns the method and property types and their expected values to test
226+
* the retrieval of types.
227+
*
228+
* @param string $method Name of the method consuming this data provider.
229+
*
230+
* @return string[]
231+
*/
232+
public function provideTypesToExpandWithPropertyOrMethod($method)
233+
{
234+
return array(
235+
array(
236+
'LinkDescriptor::setLink()',
237+
array('\phpDocumentor\LinkDescriptor::setLink()')
238+
),
239+
array(
240+
'phpDocumentor\LinkDescriptor::setLink()',
241+
array('\phpDocumentor\LinkDescriptor::setLink()')
242+
),
243+
array(
244+
'LinkDescriptor::$link',
245+
array('\phpDocumentor\LinkDescriptor::$link')
246+
),
247+
array(
248+
'phpDocumentor\LinkDescriptor::$link',
249+
array('\phpDocumentor\LinkDescriptor::$link')
250+
),
251+
);
252+
}
195253
}

0 commit comments

Comments
 (0)