Skip to content

Commit 8967807

Browse files
committed
auto fixes from ecs
1 parent d65e7b5 commit 8967807

13 files changed

+114
-150
lines changed

src/FqsenResolver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ private function isFqsen($type)
4949
* (i.e. `\phpDocumentor\Reflection\DocBlock`) based on the Namespace and aliases mentioned in the Context.
5050
*
5151
* @param string $type
52-
* @param Context $context
53-
*
5452
* @return Fqsen
55-
* @throws \InvalidArgumentException when type is not a valid FQSEN.
53+
* @throws InvalidArgumentException when type is not a valid FQSEN.
5654
*/
5755
private function resolvePartialStructuralElementName($type, Context $context)
5856
{

src/TypeResolver.php

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
namespace phpDocumentor\Reflection;
1414

1515
use phpDocumentor\Reflection\Types\Array_;
16+
use phpDocumentor\Reflection\Types\Collection;
1617
use phpDocumentor\Reflection\Types\Compound;
1718
use phpDocumentor\Reflection\Types\Context;
19+
use phpDocumentor\Reflection\Types\Integer;
1820
use phpDocumentor\Reflection\Types\Iterable_;
1921
use phpDocumentor\Reflection\Types\Nullable;
2022
use phpDocumentor\Reflection\Types\Object_;
21-
use phpDocumentor\Reflection\Types\Collection;
2223
use phpDocumentor\Reflection\Types\String_;
23-
use phpDocumentor\Reflection\Types\Integer;
2424

2525
final class TypeResolver
2626
{
@@ -42,9 +42,8 @@ final class TypeResolver
4242
/** @var integer the iterator parser is inside a collection expression context */
4343
const PARSER_IN_COLLECTION_EXPRESSION = 3;
4444

45-
4645
/** @var string[] List of recognized keywords and unto which Value Object they map */
47-
private $keywords = array(
46+
private $keywords = [
4847
'string' => Types\String_::class,
4948
'int' => Types\Integer::class,
5049
'integer' => Types\Integer::class,
@@ -69,15 +68,13 @@ final class TypeResolver
6968
'static' => Types\Static_::class,
7069
'parent' => Types\Parent_::class,
7170
'iterable' => Iterable_::class,
72-
);
71+
];
7372

7473
/** @var FqsenResolver */
7574
private $fqsenResolver;
7675

7776
/**
7877
* Initializes this TypeResolver with the means to create and resolve Fqsen objects.
79-
*
80-
* @param FqsenResolver $fqsenResolver
8178
*/
8279
public function __construct(FqsenResolver $fqsenResolver = null)
8380
{
@@ -94,13 +91,10 @@ public function __construct(FqsenResolver $fqsenResolver = null)
9491
* This method only works as expected if the namespace and aliases are set;
9592
* no dynamic reflection is being performed here.
9693
*
97-
* @param string $type The relative or absolute type.
98-
* @param Context $context
99-
*
94+
* @param string $type The relative or absolute type.
10095
* @uses Context::getNamespace() to determine with what to prefix the type name.
10196
* @uses Context::getNamespaceAliases() to check whether the first part of the relative type name should not be
102-
* replaced with another namespace.
103-
*
97+
* replaced with another namespace.
10498
* @return Type
10599
*/
106100
public function resolve($type, Context $context = null)
@@ -130,26 +124,25 @@ public function resolve($type, Context $context = null)
130124
/**
131125
* Analyse each tokens and creates types
132126
*
133-
* @param \ArrayIterator $tokens the iterator on tokens
134-
* @param Context $context
135-
* @param integer $parserContext on of self::PARSER_* constants, indicating
136-
* the context where we are in the parsing
137-
*
127+
* @param ArrayIterator $tokens the iterator on tokens
128+
* @param int $parserContext on of self::PARSER_* constants, indicating
129+
* the context where we are in the parsing
138130
* @return Type
139131
*/
140132
private function parseTypes(\ArrayIterator $tokens, Context $context, $parserContext)
141133
{
142-
$types = array();
134+
$types = [];
143135
$token = '';
144136
while ($tokens->valid()) {
145137
$token = $tokens->current();
146138

147-
if ($token == '|') {
148-
if (count($types) == 0) {
139+
if ($token === '|') {
140+
if (count($types) === 0) {
149141
throw new \RuntimeException(
150142
'A type is missing before a type separator'
151143
);
152144
}
145+
153146
if ($parserContext !== self::PARSER_IN_COMPOUND
154147
&& $parserContext !== self::PARSER_IN_ARRAY_EXPRESSION
155148
&& $parserContext !== self::PARSER_IN_COLLECTION_EXPRESSION
@@ -158,9 +151,9 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
158151
'Unexpected type separator'
159152
);
160153
}
161-
$tokens->next();
162154

163-
} else if ($token == '?') {
155+
$tokens->next();
156+
} elseif ($token === '?') {
164157
if ($parserContext !== self::PARSER_IN_COMPOUND
165158
&& $parserContext !== self::PARSER_IN_ARRAY_EXPRESSION
166159
&& $parserContext !== self::PARSER_IN_COLLECTION_EXPRESSION
@@ -173,40 +166,38 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
173166
$tokens->next();
174167
$type = $this->parseTypes($tokens, $context, self::PARSER_IN_NULLABLE);
175168
$types[] = new Nullable($type);
176-
177-
} else if ($token === '(') {
169+
} elseif ($token === '(') {
178170
$tokens->next();
179171
$type = $this->parseTypes($tokens, $context, self::PARSER_IN_ARRAY_EXPRESSION);
180172

181173
$resolvedType = new Array_($type);
182174

183175
// we generates arrays corresponding to the number of '[]'
184176
// after the ')'
185-
$numberOfArrays = (strlen($tokens->current()) -1) / 2;
186-
for ($i = 0; $i < $numberOfArrays - 1; $i++) {
177+
$numberOfArrays = (strlen($tokens->current()) - 1) / 2;
178+
for ($i = 0; $i < $numberOfArrays - 1; ++$i) {
187179
$resolvedType = new Array_($resolvedType);
188180
}
181+
189182
$types[] = $resolvedType;
190183
$tokens->next();
191-
192-
} else if ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION
184+
} elseif ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION
193185
&& $token[0] === ')'
194186
) {
195187
break;
196-
197-
} else if ($token === '<') {
188+
} elseif ($token === '<') {
198189
if (count($types) === 0) {
199190
throw new \RuntimeException(
200191
'Unexpected collection operator "<", class name is missing'
201192
);
202193
}
194+
203195
$classType = array_pop($types);
204196

205197
$types[] = $this->resolveCollection($tokens, $classType, $context);
206198

207199
$tokens->next();
208-
209-
} else if ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
200+
} elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
210201
&& ($token === '>' || $token === ',')
211202
) {
212203
break;
@@ -216,47 +207,51 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
216207
if ($parserContext === self::PARSER_IN_NULLABLE) {
217208
return $type;
218209
}
210+
219211
$types[] = $type;
220212
}
221213
}
222214

223-
if ($token == '|') {
215+
if ($token === '|') {
224216
throw new \RuntimeException(
225217
'A type is missing after a type separator'
226218
);
227219
}
228220

229-
if (count($types) == 0) {
230-
if ($parserContext == self::PARSER_IN_NULLABLE) {
221+
if (count($types) === 0) {
222+
if ($parserContext === self::PARSER_IN_NULLABLE) {
231223
throw new \RuntimeException(
232224
'A type is missing after a nullable character'
233225
);
234226
}
235-
if ($parserContext == self::PARSER_IN_ARRAY_EXPRESSION) {
227+
228+
if ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION) {
236229
throw new \RuntimeException(
237230
'A type is missing in an array expression'
238231
);
239232
}
240-
if ($parserContext == self::PARSER_IN_COLLECTION_EXPRESSION) {
233+
234+
if ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION) {
241235
throw new \RuntimeException(
242236
'A type is missing in a collection expression'
243237
);
244238
}
239+
245240
throw new \RuntimeException(
246241
'No types in a compound list'
247242
);
248-
} else if (count($types) == 1) {
243+
} elseif (count($types) === 1) {
249244
return $types[0];
250245
}
246+
251247
return new Compound($types);
252248
}
253249

254250
/**
255251
* resolve the given type into a type object
256252
*
257-
* @param string $type the type string, representing a single type
258-
* @param Context $context
259-
* @return Type|Array_|Object_
253+
* @param string $type the type string, representing a single type
254+
* @return Type|\Array_|\Object_
260255
*/
261256
private function resolveSingleType($type, Context $context)
262257
{
@@ -276,6 +271,7 @@ private function resolveSingleType($type, Context $context)
276271
'Unable to resolve type "' . $type . '", there is no known method to resolve it'
277272
);
278273
}
274+
279275
// @codeCoverageIgnoreEnd
280276
}
281277

@@ -284,8 +280,6 @@ private function resolveSingleType($type, Context $context)
284280
*
285281
* @param string $keyword
286282
* @param string $typeClassName
287-
*
288-
* @return void
289283
*/
290284
public function addKeyword($keyword, $typeClassName)
291285
{
@@ -357,8 +351,6 @@ private function isFqsen($type)
357351
* Resolves the given typed array string (i.e. `string[]`) into an Array object with the right types set.
358352
*
359353
* @param string $type
360-
* @param Context $context
361-
*
362354
* @return Array_
363355
*/
364356
private function resolveTypedArray($type, Context $context)
@@ -396,20 +388,17 @@ private function resolveTypedObject($type, Context $context = null)
396388
/**
397389
* Resolves the collection values and keys
398390
*
399-
* @param \ArrayIterator $tokens
400-
* @param Type $classType
401-
* @param Context $context
402-
* @return Array_|Collection
391+
* @return Array_|\Collection
403392
*/
404-
private function resolveCollection(\ArrayIterator $tokens, Type $classType, Context $context) {
405-
406-
$isArray = ('array' == (string) $classType);
393+
private function resolveCollection(\ArrayIterator $tokens, Type $classType, Context $context)
394+
{
395+
$isArray = ('array' === (string) $classType);
407396

408397
// allow only "array" or class name before "<"
409398
if (!$isArray
410399
&& (! $classType instanceof Object_ || $classType->getFqsen() === null)) {
411400
throw new \RuntimeException(
412-
$classType.' is not a collection'
401+
$classType . ' is not a collection'
413402
);
414403
}
415404

@@ -418,7 +407,7 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
418407
$valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
419408
$keyType = null;
420409

421-
if ($tokens->current() == ',') {
410+
if ($tokens->current() === ',') {
422411
// if we have a comma, then we just parsed the key type, not the value type
423412
$keyType = $valueType;
424413
if ($isArray) {
@@ -432,8 +421,9 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
432421
'An array can have only integers or strings as keys'
433422
);
434423
}
424+
435425
if ($keyType instanceof Compound) {
436-
foreach($keyType->getIterator() as $item) {
426+
foreach ($keyType->getIterator() as $item) {
437427
if (! $item instanceof String_ &&
438428
! $item instanceof Integer
439429
) {
@@ -444,22 +434,24 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
444434
}
445435
}
446436
}
437+
447438
$tokens->next();
448439
// now let's parse the value type
449440
$valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
450441
}
451442

452443
if ($tokens->current() !== '>') {
453-
if ($tokens->current() == '') {
444+
if ($tokens->current() === '') {
454445
throw new \RuntimeException(
455446
'Collection: ">" is missing'
456447
);
457448
}
458449

459450
throw new \RuntimeException(
460-
'Unexpected character "'.$tokens->current().'", ">" is missing'
451+
'Unexpected character "' . $tokens->current() . '", ">" is missing'
461452
);
462453
}
454+
463455
if ($isArray) {
464456
return new Array_($valueType, $keyType);
465457
}
@@ -470,8 +462,6 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
470462
}
471463

472464
/**
473-
* @param Object_ $object
474-
* @param Type $valueType
475465
* @param Type|null $keyType
476466
* @return Collection
477467
*/

src/Types/AbstractList.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
/**
1818
* Represents a list of values. This is an abstract class for Array_ and Collection.
19-
*
2019
*/
2120
abstract class AbstractList implements Type
2221
{
@@ -31,9 +30,6 @@ abstract class AbstractList implements Type
3130

3231
/**
3332
* Initializes this representation of an array with the given Type.
34-
*
35-
* @param Type $valueType
36-
* @param Type $keyType
3733
*/
3834
public function __construct(Type $valueType = null, Type $keyType = null)
3935
{
@@ -42,9 +38,8 @@ public function __construct(Type $valueType = null, Type $keyType = null)
4238
}
4339

4440
$this->valueType = $valueType;
45-
$this->defaultKeyType = new Compound([ new String_(), new Integer() ]);
41+
$this->defaultKeyType = new Compound([new String_(), new Integer()]);
4642
$this->keyType = $keyType;
47-
4843
}
4944

5045
/**
@@ -57,6 +52,7 @@ public function getKeyType()
5752
if ($this->keyType === null) {
5853
return $this->defaultKeyType;
5954
}
55+
6056
return $this->keyType;
6157
}
6258

@@ -78,7 +74,7 @@ public function getValueType()
7874
public function __toString()
7975
{
8076
if ($this->keyType) {
81-
return 'array<'.$this->keyType.','.$this->valueType.'>';
77+
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
8278
}
8379

8480
if ($this->valueType instanceof Mixed_) {

0 commit comments

Comments
 (0)