Skip to content

Commit c758c74

Browse files
committed
Some fixes
1 parent afd87c2 commit c758c74

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

src/TypeResolver.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,8 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser
208208
}
209209

210210
$tokens->next();
211-
$token = $tokens->current();
212211

213-
if ($token === self::OPERATOR_ARRAY) {
214-
$tokens->next();
215-
$resolvedType = new Array_($type);
216-
} else {
217-
$resolvedType = new Expression_($type);
218-
}
212+
$resolvedType = new Expression_($type);
219213

220214
$types[] = $resolvedType;
221215
} elseif ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION && $token[0] === ')') {
@@ -242,8 +236,13 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser
242236
) {
243237
break;
244238
} elseif ($token === self::OPERATOR_ARRAY) {
245-
$last = array_key_last($types);
246-
$types[$last] = new Array_($types[$last]);
239+
end($types);
240+
$last = key($types);
241+
$lastItem = $types[$last];
242+
if ($lastItem instanceof Expression_) {
243+
$lastItem = $lastItem->getValueType();
244+
}
245+
$types[$last] = new Array_($lastItem);
247246

248247
$tokens->next();
249248
} else {

src/Types/AbstractList.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,24 @@ public function getValueType() : Type
5858
{
5959
return $this->valueType;
6060
}
61+
62+
/**
63+
* Returns a rendered output of the Type as it would be used in a DocBlock.
64+
*/
65+
public function __toString() : string
66+
{
67+
if ($this->keyType) {
68+
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
69+
}
70+
71+
if ($this->valueType instanceof Mixed_) {
72+
return 'array';
73+
}
74+
75+
if ($this->valueType instanceof Compound) {
76+
return '(' . $this->valueType . ')[]';
77+
}
78+
79+
return $this->valueType . '[]';
80+
}
6181
}

src/Types/Array_.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,4 @@
2424
*/
2525
final class Array_ extends AbstractList
2626
{
27-
/**
28-
* Returns a rendered output of the Type as it would be used in a DocBlock.
29-
*/
30-
public function __toString() : string
31-
{
32-
if ($this->keyType) {
33-
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
34-
}
35-
36-
if ($this->valueType instanceof Mixed_) {
37-
return 'array';
38-
}
39-
40-
if ($this->valueType instanceof Compound) {
41-
return '(' . $this->valueType . ')[]';
42-
}
43-
44-
return $this->valueType . '[]';
45-
}
4627
}

src/Types/Expression_.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,33 @@
1313

1414
namespace phpDocumentor\Reflection\Types;
1515

16+
use phpDocumentor\Reflection\Type;
17+
1618
/**
17-
* Represents an array type as described in the PSR-5, the PHPDoc Standard.
19+
* Represents an expression type as described in the PSR-5, the PHPDoc Standard.
1820
*
1921
*/
20-
final class Expression_ extends AbstractList
22+
final class Expression_ implements Type
2123
{
24+
/** @var Type */
25+
protected $valueType;
26+
27+
/**
28+
* Initializes this representation of an array with the given Type.
29+
*/
30+
public function __construct(Type $valueType)
31+
{
32+
$this->valueType = $valueType;
33+
}
34+
35+
/**
36+
* Returns the value for the keys of this array.
37+
*/
38+
public function getValueType() : Type
39+
{
40+
return $this->valueType;
41+
}
42+
2243
/**
2344
* Returns a rendered output of the Type as it would be used in a DocBlock.
2445
*/

0 commit comments

Comments
 (0)