Skip to content

bump phpstan to master #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
all-build-${{ hashFiles('**/composer.lock') }}
all-build-
- name: Code style check
uses: phpDocumentor/coding-standard@v1.0.0
uses: phpDocumentor/coding-standard@master
with:
args: -s

Expand All @@ -153,7 +153,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: analyse src --level max --configuration phpstan.neon
args: analyse src --configuration phpstan.neon

psalm:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ phpcbf:

.PHONY: phpstan
phpstan:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --level max --configuration phpstan.neon
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --configuration phpstan.neon

.PHONY: psaml
psalm:
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ includes:
- /composer/vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: max
ignoreErrors:
# false positive
- '#Method phpDocumentor\Reflection\DocBlock\Tags\Method::filterArguments() should return array<array> but returns array<array|string>#'
- '#Call to static method Webmozart\\Assert\\Assert::implementsInterface\(\) with class-string#'
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<RedundantConditionGivenDocblockType>
<errorLevel type="info">
<!-- Psalm is very strict and believe that because we documented a type, it is redundant to assert it -->
<file name="src/DocBlock/StandardTagFactory.php"/>
</errorLevel>
</RedundantConditionGivenDocblockType>
</issueHandlers>
</psalm>
2 changes: 0 additions & 2 deletions src/DocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public function getTagsByName(string $name) : array
{
$result = [];

/** @var Tag $tag */
foreach ($this->getTags() as $tag) {
if ($tag->getName() !== $name) {
continue;
Expand All @@ -169,7 +168,6 @@ public function getTagsByName(string $name) : array
*/
public function hasTag(string $name) : bool
{
/** @var Tag $tag */
foreach ($this->getTags() as $tag) {
if ($tag->getName() === $name) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/DocBlock/DescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function count;
use function explode;
use function implode;
Expand All @@ -27,6 +26,7 @@
use function strpos;
use function substr;
use function trim;
use const PREG_SPLIT_DELIM_CAPTURE;

/**
* Creates a new Description object given a body of text.
Expand Down Expand Up @@ -128,6 +128,7 @@ private function lex(string $contents) : array
PREG_SPLIT_DELIM_CAPTURE
);
Assert::isArray($parts);

return $parts;
}

Expand Down
3 changes: 2 additions & 1 deletion src/DocBlock/ExampleFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace phpDocumentor\Reflection\DocBlock;

use phpDocumentor\Reflection\DocBlock\Tags\Example;
use const DIRECTORY_SEPARATOR;
use function array_slice;
use function file;
use function getcwd;
Expand All @@ -23,6 +22,7 @@
use function rtrim;
use function sprintf;
use function trim;
use const DIRECTORY_SEPARATOR;

/**
* Class used to find an example file's location based on a given ExampleDescriptor.
Expand Down Expand Up @@ -122,6 +122,7 @@ private function getExampleFileContents(string $filename) : ?array
}

$lines = $normalizedPath && is_readable($normalizedPath) ? file($normalizedPath) : false;

return $lines !== false ? $lines : null;
}

Expand Down
2 changes: 2 additions & 0 deletions src/DocBlock/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function getDocComment(DocBlock $docblock) : string
}

$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);

return $comment . $indent . ' */';
}

Expand Down Expand Up @@ -127,6 +128,7 @@ private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wra
: '');
if ($wrapLength !== null) {
$text = wordwrap($text, $wrapLength);

return $text;
}

Expand Down
25 changes: 8 additions & 17 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ final class StandardTagFactory implements TagFactory
public const REGEX_TAGNAME = '[\w\-\_\\\\:]+';

/**
* @var string[] An array with a tag as a key, and an
* FQCN to a class that handles it as an array value.
* @var array<class-string<StaticMethod>> An array with a tag as a key, and an
* FQCN to a class that handles it as an array value.
*/
private $tagHandlerMappings = [
'author' => Author::class,
Expand All @@ -97,7 +97,7 @@ final class StandardTagFactory implements TagFactory
];

/**
* @var string[] An array with a anotation s a key, and an
* @var array<class-string<StaticMethod>> An array with a anotation s a key, and an
* FQCN to a class that handles it as an array value.
*/
private $annotationMappings = [];
Expand Down Expand Up @@ -125,7 +125,7 @@ final class StandardTagFactory implements TagFactory
*
* @see self::registerTagHandler() to add a new tag handler to the existing default list.
*
* @param string[] $tagHandlers
* @param array<class-string<StaticMethod>> $tagHandlers
*/
public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers = null)
{
Expand All @@ -137,9 +137,6 @@ public function __construct(FqsenResolver $fqsenResolver, ?array $tagHandlers =
$this->addService($fqsenResolver, FqsenResolver::class);
}

/**
* {@inheritDoc}
*/
public function create(string $tagLine, ?TypeContext $context = null) : Tag
{
if (!$context) {
Expand All @@ -152,29 +149,22 @@ public function create(string $tagLine, ?TypeContext $context = null) : Tag
}

/**
* {@inheritDoc}
* @param mixed $value
*/
public function addParameter(string $name, $value) : void
{
$this->serviceLocator[$name] = $value;
}

/**
* {@inheritDoc}
*/
public function addService(object $service, ?string $alias = null) : void
{
$this->serviceLocator[$alias ?: get_class($service)] = $service;
}

/**
* {@inheritDoc}
*/
public function registerTagHandler(string $tagName, string $handler) : void
{
Assert::stringNotEmpty($tagName);
Assert::classExists($handler);
/** @var object $handler stupid hack to make phpstan happy. */
Assert::implementsInterface($handler, StaticMethod::class);

if (strpos($tagName, '\\') && $tagName[0] !== '\\') {
Expand Down Expand Up @@ -220,9 +210,10 @@ private function createTag(string $body, string $name, TypeContext $context) : T
);

try {
/** @var callable $callable */
$callable = [$handlerClassName, 'create'];
$tag = call_user_func_array($callable, $arguments);
Assert::isCallable($callable);
$tag = call_user_func_array($callable, $arguments);

return $tag ?? InvalidTag::create($body, $name);
} catch (InvalidArgumentException $e) {
return InvalidTag::create($body, $name)->withError($e);
Expand Down
7 changes: 4 additions & 3 deletions src/DocBlock/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Reflection\DocBlock;

use InvalidArgumentException;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
use phpDocumentor\Reflection\Types\Context as TypeContext;

interface TagFactory
Expand Down Expand Up @@ -69,9 +70,9 @@ public function addService(object $service) : void;
* to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement
* the {@see Tag} interface (and thus the create method).
*
* @param string $tagName Name of tag to register a handler for. When registering a namespaced tag,
* the full name, along with a prefixing slash MUST be provided.
* @param string $handler FQCN of handler.
* @param string $tagName Name of tag to register a handler for. When registering a namespaced
* tag, the full name, along with a prefixing slash MUST be provided.
* @param class-string<StaticMethod> $handler FQCN of handler.
*
* @throws InvalidArgumentException If the tag name is not a string.
* @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace phpDocumentor\Reflection\DocBlock\Tags;

use InvalidArgumentException;
use const FILTER_VALIDATE_EMAIL;
use function filter_var;
use function preg_match;
use function strlen;
use function trim;
use const FILTER_VALIDATE_EMAIL;

/**
* Reflection class for an {@}author tag in a Docblock.
Expand Down
3 changes: 0 additions & 3 deletions src/DocBlock/Tags/Covers.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function __construct(Fqsen $refers, ?Description $description = null)
$this->description = $description;
}

/**
* {@inheritdoc}
*/
public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
Expand Down
1 change: 1 addition & 0 deletions src/DocBlock/Tags/Deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function create(
}

Assert::notNull($descriptionFactory);

return new static(
$matches[1],
$descriptionFactory->create($matches[2] ?? '', $context)
Expand Down
3 changes: 0 additions & 3 deletions src/DocBlock/Tags/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public function getDescription() : ?string
return $this->content;
}

/**
* {@inheritdoc}
*/
public static function create(string $body) : ?Tag
{
// File component: File path in quotes or File URI / Source information
Expand Down
3 changes: 0 additions & 3 deletions src/DocBlock/Tags/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public function __construct(string $link, ?Description $description = null)
$this->description = $description;
}

/**
* {@inheritdoc}
*/
public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
Expand Down
34 changes: 18 additions & 16 deletions src/DocBlock/Tags/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ final class Method extends BaseTag implements Factory\StaticMethod
/** @var string */
private $methodName = '';

/** @var string[][] */
/**
* @phpstan-var array<int, array{name: string, type: Type}>
* @var array<int, array<string, Type|string>>
*/
private $arguments = [];

/** @var bool */
Expand All @@ -54,9 +57,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
private $returnType;

/**
* @param mixed[][] $arguments
* @param array<int, array<string, Type|string>> $arguments
*
* @psalm-param array<int, array<string, string|Type>|string> $arguments
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*/
public function __construct(
string $methodName,
Expand All @@ -78,9 +81,6 @@ public function __construct(
$this->description = $description;
}

/**
* {@inheritdoc}
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
Expand Down Expand Up @@ -137,7 +137,7 @@ public static function create(
return null;
}

[, $static, $returnType, $methodName, $arguments, $description] = $matches;
[, $static, $returnType, $methodName, $argumentLines, $description] = $matches;

$static = $static === 'static';

Expand All @@ -148,9 +148,11 @@ public static function create(
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);

if ($arguments !== '') {
$arguments = explode(',', $arguments);
foreach ($arguments as &$argument) {
/** @phpstan-var array<int, array{name: string, type: Type}> $arguments */
$arguments = [];
if ($argumentLines !== '') {
$argumentsExploded = explode(',', $argumentLines);
foreach ($argumentsExploded as $argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
Expand All @@ -164,10 +166,8 @@ public static function create(
}
}

$argument = ['name' => $argumentName, 'type' => $argumentType];
$arguments[] = ['name' => $argumentName, 'type' => $argumentType];
}
} else {
$arguments = [];
}

return new static($methodName, $arguments, $returnType, $static, $description);
Expand All @@ -182,7 +182,9 @@ public function getMethodName() : string
}

/**
* @return string[][]
* @return array<int, array<string, Type|string>>
*
* @phpstan-return array<int, array{name: string, type: Type}>
*/
public function getArguments() : array
{
Expand Down Expand Up @@ -223,8 +225,8 @@ public function __toString() : string
*
* @return mixed[][]
*
* @psalm-param array<int, array<string, string|Type>|string> $arguments
* @psalm-return array<int, array<string, string|Type>> $arguments
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
* @phpstan-return array<int, array{name: string, type: Type}>
*/
private function filterArguments(array $arguments = []) : array
{
Expand Down
Loading