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
View File
@@ -22,6 +22,7 @@ script:
- vendor/bin/phpunit --coverage-clover=coverage.xml -v
# coding style
- if [[ $STATIC_ANALYSIS != "" ]]; then temp/ecs/bin/ecs check src tests; fi
- if [[ $STATIC_ANALYSIS != "" ]]; then vendor/bin/phpstan analyse src --level max --configuration phpstan.neon; fi
after_script:
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
+6 -5
View File
@@ -15,6 +15,12 @@
"phpdocumentor/type-resolver": "^0.4",
"webmozart/assert": "^1.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4",
"doctrine/instantiator": "^1.0",
"phpstan/phpstan": "^0.9.0"
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": "src"
@@ -25,11 +31,6 @@
"phpDocumentor\\Reflection\\": "tests/unit"
}
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4",
"doctrine/instantiator": "^1.0"
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
Generated
+984 -1
View File
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
parameters:
ignoreErrors:
# false positive
- '#Call to an undefined method object::getDocComment\(\)#'
- '#Cannot call method render\(\) on phpDocumentor\\Reflection\\DocBlock\\Description\|string#'
- '#Calling method create\(\) on possibly null value of type phpDocumentor\\Reflection\\DocBlock\\DescriptionFactory\|null#'
- '#Calling method resolve\(\) on possibly null value of type phpDocumentor\\Reflection\\(TypeResolver|FqsenResolver)\|null#'
# nested parents
- '#Calling method render\(\) on possibly null value of type phpDocumentor\\Reflection\\DocBlock\\Description\|string\|null#'
+7 -7
View File
@@ -22,16 +22,16 @@ final class DocBlock
private $summary = '';
/** @var DocBlock\Description The actual description for this docblock. */
private $description = null;
private $description;
/** @var Tag[] An array containing all the tags in this docblock; except inline. */
private $tags = [];
/** @var Types\Context Information about the context of this DocBlock. */
private $context = null;
/** @var Types\Context|null Information about the context of this DocBlock. */
private $context;
/** @var Location Information about the location of this DocBlock. */
private $location = null;
/** @var Location|null Information about the location of this DocBlock. */
private $location;
/** @var bool Is this DocBlock (the start of) a template? */
private $isTemplateStart = false;
@@ -81,7 +81,7 @@ final class DocBlock
/**
* Returns the current context.
*/
public function getContext(): Types\Context
public function getContext(): ?Types\Context
{
return $this->context;
}
@@ -182,7 +182,7 @@ final class DocBlock
/**
* Remove a tag from this DocBlock.
*
* @param Tag $tag The tag to remove.
* @param Tag $tagToRemove The tag to remove.
*/
public function removeTag(Tag $tagToRemove): void
{
+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();
}
+1 -1
View File
@@ -207,7 +207,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
* @param string $tags Tag block to parse.
* @param Types\Context $context Context of the parsed Tag
*
* @return DocBlock\Tag[]
* @return DocBlock\Tag[]|string[]|null[]
*/
private function parseTagBlock(string $tags, Types\Context $context): array
{