Fix tests and linting errors after merging in release 4.x

This commit is contained in:
Mike van Riel
2019-12-27 21:38:28 +01:00
parent 1a5d9a2dbc
commit b668892da4
10 changed files with 112 additions and 87 deletions
+7 -4
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -43,7 +45,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
bool $isVariadic = false,
?Description $description = null
) {
$this->name = 'param';
$this->name = 'param';
$this->variableName = $variableName;
$this->type = $type;
$this->isVariadic = $isVariadic;
@@ -63,9 +65,10 @@ final class Param extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
$isVariadic = false;
+7 -5
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,7 +40,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property';
$this->name = 'property';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -57,10 +59,10 @@ final class Property extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+7 -5
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,7 +40,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property-read';
$this->name = 'property-read';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -57,10 +59,10 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+6 -5
View File
@@ -21,6 +21,7 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
@@ -39,7 +40,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property-write';
$this->name = 'property-write';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -58,10 +59,10 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+7 -8
View File
@@ -19,17 +19,16 @@ use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use function preg_split;
/**
* Reflection class for a {@}return tag in a Docblock.
*/
final class Return_ extends TagWithType implements Factory\StaticMethod
{
public function __construct(Type $type, Description $description = null)
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'return';
$this->type = $type;
$this->name = 'return';
$this->type = $type;
$this->description = $description;
}
@@ -45,16 +44,16 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($type, $description) = self::extractTypeFromBody($body);
[$type, $description] = self::extractTypeFromBody($body);
$type = $typeResolver->resolve($type, $context);
$type = $typeResolver->resolve($type, $context);
$description = $descriptionFactory->create($description, $context);
return new static($type, $description);
}
public function __toString() :string
public function __toString() : string
{
return $this->type . ' ' . (string) $this->description;
return ($this->type ?: 'mixed') . ' ' . (string) $this->description;
}
}
+13 -7
View File
@@ -8,33 +8,36 @@ declare(strict_types=1);
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Type;
use function in_array;
use function strlen;
use function substr;
use function trim;
abstract class TagWithType extends BaseTag
{
/** @var Type */
/** @var ?Type */
protected $type;
/**
* Returns the type section of the variable.
*
* @return Type
*/
public function getType()
public function getType() : ?Type
{
return $this->type;
}
/**
* @return string[]
*/
protected static function extractTypeFromBody(string $body) : array
{
$type = '';
$type = '';
$nestingLevel = 0;
for ($i = 0; $i < strlen($body); $i++) {
$character = $body[$i];
@@ -46,9 +49,12 @@ abstract class TagWithType extends BaseTag
$type .= $character;
if (in_array($character, ['<', '(', '[', '{'])) {
$nestingLevel++;
continue;
}
if (in_array($character, ['>', ')', ']', '}'])) {
$nestingLevel--;
continue;
}
}
+5 -6
View File
@@ -19,17 +19,16 @@ use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use function preg_split;
/**
* Reflection class for a {@}throws tag in a Docblock.
*/
final class Throws extends TagWithType implements Factory\StaticMethod
{
public function __construct(Type $type, Description $description = null)
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'throws';
$this->type = $type;
$this->name = 'throws';
$this->type = $type;
$this->description = $description;
}
@@ -45,9 +44,9 @@ final class Throws extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($type, $description) = self::extractTypeFromBody($body);
[$type, $description] = self::extractTypeFromBody($body);
$type = $typeResolver->resolve($type, $context);
$type = $typeResolver->resolve($type, $context);
$description = $descriptionFactory->create($description, $context);
return new static($type, $description);
+9 -6
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,10 +40,10 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'var';
$this->name = 'var';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
$this->type = $type;
$this->description = $description;
}
/**
@@ -57,9 +59,10 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
[$firstPart, $body] = self::extractTypeFromBody($body);
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
// if the first item that is encountered is not a variable; it is a type