Add PHPStan and bump to max level (#139)

* composer: put require- together

* add phpstan

* add phpstan to travis

* phpstan fixes

* phpstan fixes

* phpstan fixes

* drop null defaults since every property is null by default

* DescriptionFactory: fix parse nullable type

* travis: add phpstan max

* travis: fix phpstan config
This commit is contained in:
Tomáš Votruba
2017-12-02 19:12:29 +01:00
committed by Jaap van Otterdijk
parent c19b4d170c
commit bab88701ea
22 changed files with 1028 additions and 41 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ class DescriptionFactory
*
* @return string[]|Tag[]
*/
private function parse($tokens, TypeContext $context)
private function parse($tokens, ?TypeContext $context = null): array
{
$count = count($tokens);
$tagCount = 0;
+2 -2
View File
@@ -30,10 +30,10 @@ class Serializer
protected $isFirstLineIndented = true;
/** @var int|null The max length of a line. */
protected $lineLength = null;
protected $lineLength;
/** @var DocBlock\Tags\Formatter A custom tag formatter. */
protected $tagFormatter = null;
protected $tagFormatter;
/**
* Create a Serializer instance.
+1 -1
View File
@@ -105,7 +105,7 @@ final class StandardTagFactory implements TagFactory
/**
* {@inheritDoc}
*/
public function create(string $tagLine, ?TypeContext $context = null): Tag
public function create(string $tagLine, ?TypeContext $context = null): ?Tag
{
if (! $context) {
$context = new TypeContext('');
+1 -4
View File
@@ -70,11 +70,8 @@ final class Author extends BaseTag implements Factory\StaticMethod
/**
* Attempts to create a new Author object based on †he tag body.
*
*
* @return static
*/
public static function create(string $body)
public static function create(string $body): ?self
{
$splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches);
if (!$splitTagContent) {
+1 -1
View File
@@ -28,7 +28,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
protected $name = 'covers';
/** @var Fqsen */
private $refers = null;
private $refers;
/**
* Initializes this tag.
+2 -2
View File
@@ -69,7 +69,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): Method {
): ?self {
Assert::stringNotEmpty($body);
Assert::allNotNull([ $typeResolver, $descriptionFactory ]);
@@ -125,7 +125,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
[, $static, $returnType, $methodName, $arguments, $description] = $matches;
$static = $static === 'static';
$static = $static === 'static';
if ($returnType === '') {
$returnType = 'void';
+1 -1
View File
@@ -28,7 +28,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
/** @var string */
protected $name = 'param';
/** @var Type */
/** @var Type|null */
private $type;
/** @var string */
+1 -1
View File
@@ -28,7 +28,7 @@ class Property extends BaseTag implements Factory\StaticMethod
/** @var string */
protected $name = 'property';
/** @var Type */
/** @var Type|null */
private $type;
/** @var string */
+1 -1
View File
@@ -28,7 +28,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
/** @var string */
protected $name = 'property-read';
/** @var Type */
/** @var Type|null */
private $type;
/** @var string */
+1 -1
View File
@@ -28,7 +28,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
/** @var string */
protected $name = 'property-write';
/** @var Type */
/** @var Type|null */
private $type;
/** @var string */
+1 -1
View File
@@ -30,7 +30,7 @@ class See extends BaseTag implements Factory\StaticMethod
protected $name = 'see';
/** @var Reference */
protected $refers = null;
protected $refers;
/**
* Initializes this tag.
+2 -4
View File
@@ -15,6 +15,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
@@ -52,14 +53,11 @@ final class Since extends BaseTag implements Factory\StaticMethod
$this->description = $description;
}
/**
* @return static
*/
public static function create(
?string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) {
): ?self {
if (empty($body)) {
return new static();
}
+1 -1
View File
@@ -30,7 +30,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
private $startingLine = 1;
/** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */
private $lineCount = null;
private $lineCount;
public function __construct($startingLine, $lineCount = null, ?Description $description = null)
{
+1 -1
View File
@@ -28,7 +28,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
protected $name = 'uses';
/** @var Fqsen */
protected $refers = null;
protected $refers;
/**
* Initializes this tag.
+1 -1
View File
@@ -28,7 +28,7 @@ class Var_ extends BaseTag implements Factory\StaticMethod
/** @var string */
protected $name = 'var';
/** @var Type */
/** @var Type|null */
private $type;
/** @var string */
+1 -4
View File
@@ -52,14 +52,11 @@ final class Version extends BaseTag implements Factory\StaticMethod
$this->description = $description;
}
/**
* @return static
*/
public static function create(
?string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
) {
): ?self {
if (empty($body)) {
return new static();
}