Skip to content

Commit b668892

Browse files
committed
Fix tests and linting errors after merging in release 4.x
1 parent 1a5d9a2 commit b668892

File tree

10 files changed

+112
-87
lines changed

10 files changed

+112
-87
lines changed

src/DocBlock/Tags/Param.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
use Webmozart\Assert\Assert;
2222
use const PREG_SPLIT_DELIM_CAPTURE;
2323
use function array_shift;
24+
use function array_unshift;
2425
use function implode;
2526
use function preg_split;
27+
use function strlen;
2628
use function strpos;
2729
use function substr;
2830

@@ -43,7 +45,7 @@ public function __construct(
4345
bool $isVariadic = false,
4446
?Description $description = null
4547
) {
46-
$this->name = 'param';
48+
$this->name = 'param';
4749
$this->variableName = $variableName;
4850
$this->type = $type;
4951
$this->isVariadic = $isVariadic;
@@ -63,9 +65,10 @@ public static function create(
6365
Assert::notNull($typeResolver);
6466
Assert::notNull($descriptionFactory);
6567

66-
list($firstPart, $body) = self::extractTypeFromBody($body);
67-
$type = null;
68-
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
68+
[$firstPart, $body] = self::extractTypeFromBody($body);
69+
70+
$type = null;
71+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
6972
$variableName = '';
7073
$isVariadic = false;
7174

src/DocBlock/Tags/Property.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
use Webmozart\Assert\Assert;
2222
use const PREG_SPLIT_DELIM_CAPTURE;
2323
use function array_shift;
24+
use function array_unshift;
2425
use function implode;
2526
use function preg_split;
27+
use function strlen;
2628
use function strpos;
2729
use function substr;
2830

@@ -38,7 +40,7 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
3840
{
3941
Assert::string($variableName);
4042

41-
$this->name = 'property';
43+
$this->name = 'property';
4244
$this->variableName = $variableName;
4345
$this->type = $type;
4446
$this->description = $description;
@@ -57,10 +59,10 @@ public static function create(
5759
Assert::notNull($typeResolver);
5860
Assert::notNull($descriptionFactory);
5961

60-
list($firstPart, $body) = self::extractTypeFromBody($body);
61-
$type = null;
62-
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
63-
$variableName = '';
62+
[$firstPart, $body] = self::extractTypeFromBody($body);
63+
$type = null;
64+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
$variableName = '';
6466

6567
// if the first item that is encountered is not a variable; it is a type
6668
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {

src/DocBlock/Tags/PropertyRead.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
use Webmozart\Assert\Assert;
2222
use const PREG_SPLIT_DELIM_CAPTURE;
2323
use function array_shift;
24+
use function array_unshift;
2425
use function implode;
2526
use function preg_split;
27+
use function strlen;
2628
use function strpos;
2729
use function substr;
2830

@@ -38,7 +40,7 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
3840
{
3941
Assert::string($variableName);
4042

41-
$this->name = 'property-read';
43+
$this->name = 'property-read';
4244
$this->variableName = $variableName;
4345
$this->type = $type;
4446
$this->description = $description;
@@ -57,10 +59,10 @@ public static function create(
5759
Assert::notNull($typeResolver);
5860
Assert::notNull($descriptionFactory);
5961

60-
list($firstPart, $body) = self::extractTypeFromBody($body);
61-
$type = null;
62-
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
63-
$variableName = '';
62+
[$firstPart, $body] = self::extractTypeFromBody($body);
63+
$type = null;
64+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
$variableName = '';
6466

6567
// if the first item that is encountered is not a variable; it is a type
6668
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {

src/DocBlock/Tags/PropertyWrite.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Webmozart\Assert\Assert;
2222
use const PREG_SPLIT_DELIM_CAPTURE;
2323
use function array_shift;
24+
use function array_unshift;
2425
use function implode;
2526
use function preg_split;
2627
use function strlen;
@@ -39,7 +40,7 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
3940
{
4041
Assert::string($variableName);
4142

42-
$this->name = 'property-write';
43+
$this->name = 'property-write';
4344
$this->variableName = $variableName;
4445
$this->type = $type;
4546
$this->description = $description;
@@ -58,10 +59,10 @@ public static function create(
5859
Assert::notNull($typeResolver);
5960
Assert::notNull($descriptionFactory);
6061

61-
list($firstPart, $body) = self::extractTypeFromBody($body);
62-
$type = null;
63-
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
64-
$variableName = '';
62+
[$firstPart, $body] = self::extractTypeFromBody($body);
63+
$type = null;
64+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
$variableName = '';
6566

6667
// if the first item that is encountered is not a variable; it is a type
6768
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {

src/DocBlock/Tags/Return_.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
use phpDocumentor\Reflection\TypeResolver;
2020
use phpDocumentor\Reflection\Types\Context as TypeContext;
2121
use Webmozart\Assert\Assert;
22-
use function preg_split;
2322

2423
/**
2524
* Reflection class for a {@}return tag in a Docblock.
2625
*/
2726
final class Return_ extends TagWithType implements Factory\StaticMethod
2827
{
29-
public function __construct(Type $type, Description $description = null)
28+
public function __construct(Type $type, ?Description $description = null)
3029
{
31-
$this->name = 'return';
32-
$this->type = $type;
30+
$this->name = 'return';
31+
$this->type = $type;
3332
$this->description = $description;
3433
}
3534

@@ -45,16 +44,16 @@ public static function create(
4544
Assert::notNull($typeResolver);
4645
Assert::notNull($descriptionFactory);
4746

48-
list($type, $description) = self::extractTypeFromBody($body);
47+
[$type, $description] = self::extractTypeFromBody($body);
4948

50-
$type = $typeResolver->resolve($type, $context);
49+
$type = $typeResolver->resolve($type, $context);
5150
$description = $descriptionFactory->create($description, $context);
5251

5352
return new static($type, $description);
5453
}
5554

56-
public function __toString() :string
55+
public function __toString() : string
5756
{
58-
return $this->type . ' ' . (string) $this->description;
57+
return ($this->type ?: 'mixed') . ' ' . (string) $this->description;
5958
}
6059
}

src/DocBlock/Tags/TagWithType.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,36 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*
11-
* @copyright 2010-2015 Mike van Riel<[email protected]>
12-
* @license http://www.opensource.org/licenses/mit-license.php MIT
1311
* @link http://phpdoc.org
1412
*/
1513

1614
namespace phpDocumentor\Reflection\DocBlock\Tags;
1715

1816
use phpDocumentor\Reflection\Type;
17+
use function in_array;
18+
use function strlen;
19+
use function substr;
20+
use function trim;
1921

2022
abstract class TagWithType extends BaseTag
2123
{
22-
/** @var Type */
24+
/** @var ?Type */
2325
protected $type;
2426

2527
/**
2628
* Returns the type section of the variable.
27-
*
28-
* @return Type
2929
*/
30-
public function getType()
30+
public function getType() : ?Type
3131
{
3232
return $this->type;
3333
}
3434

35+
/**
36+
* @return string[]
37+
*/
3538
protected static function extractTypeFromBody(string $body) : array
3639
{
37-
$type = '';
40+
$type = '';
3841
$nestingLevel = 0;
3942
for ($i = 0; $i < strlen($body); $i++) {
4043
$character = $body[$i];
@@ -46,9 +49,12 @@ protected static function extractTypeFromBody(string $body) : array
4649
$type .= $character;
4750
if (in_array($character, ['<', '(', '[', '{'])) {
4851
$nestingLevel++;
52+
continue;
4953
}
54+
5055
if (in_array($character, ['>', ')', ']', '}'])) {
5156
$nestingLevel--;
57+
continue;
5258
}
5359
}
5460

src/DocBlock/Tags/Throws.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
use phpDocumentor\Reflection\TypeResolver;
2020
use phpDocumentor\Reflection\Types\Context as TypeContext;
2121
use Webmozart\Assert\Assert;
22-
use function preg_split;
2322

2423
/**
2524
* Reflection class for a {@}throws tag in a Docblock.
2625
*/
2726
final class Throws extends TagWithType implements Factory\StaticMethod
2827
{
29-
public function __construct(Type $type, Description $description = null)
28+
public function __construct(Type $type, ?Description $description = null)
3029
{
31-
$this->name = 'throws';
32-
$this->type = $type;
30+
$this->name = 'throws';
31+
$this->type = $type;
3332
$this->description = $description;
3433
}
3534

@@ -45,9 +44,9 @@ public static function create(
4544
Assert::notNull($typeResolver);
4645
Assert::notNull($descriptionFactory);
4746

48-
list($type, $description) = self::extractTypeFromBody($body);
47+
[$type, $description] = self::extractTypeFromBody($body);
4948

50-
$type = $typeResolver->resolve($type, $context);
49+
$type = $typeResolver->resolve($type, $context);
5150
$description = $descriptionFactory->create($description, $context);
5251

5352
return new static($type, $description);

src/DocBlock/Tags/Var_.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
use Webmozart\Assert\Assert;
2222
use const PREG_SPLIT_DELIM_CAPTURE;
2323
use function array_shift;
24+
use function array_unshift;
2425
use function implode;
2526
use function preg_split;
27+
use function strlen;
2628
use function strpos;
2729
use function substr;
2830

@@ -38,10 +40,10 @@ public function __construct(?string $variableName, ?Type $type = null, ?Descript
3840
{
3941
Assert::string($variableName);
4042

41-
$this->name = 'var';
43+
$this->name = 'var';
4244
$this->variableName = $variableName;
43-
$this->type = $type;
44-
$this->description = $description;
45+
$this->type = $type;
46+
$this->description = $description;
4547
}
4648

4749
/**
@@ -57,9 +59,10 @@ public static function create(
5759
Assert::notNull($typeResolver);
5860
Assert::notNull($descriptionFactory);
5961

60-
list($firstPart, $body) = self::extractTypeFromBody($body);
61-
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
62-
$type = null;
62+
[$firstPart, $body] = self::extractTypeFromBody($body);
63+
64+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
65+
$type = null;
6366
$variableName = '';
6467

6568
// if the first item that is encountered is not a variable; it is a type

0 commit comments

Comments
 (0)