Skip to content
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

Add vimeo/psalm to the build and fixed detected static analysis issues that were detected by it #423

Merged
merged 7 commits into from
May 26, 2018

Conversation

muglug
Copy link
Contributor

@muglug muglug commented May 11, 2018

This adds Psalm to BetterReflection's build, fixing issues it found (mainly by adding supplementary docblocks).

If you'd rather those docblocks be asserts, I'm happy to update.

@@ -340,7 +345,7 @@ public function getMethods(?int $filter = null) : array
array_filter(
$this->getMethodsIndexedByName(),
function (ReflectionMethod $method) use ($filter) {
return $filter & $method->getModifiers();
return (bool) ($filter & $method->getModifiers());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closure should have return type hint as well.

@@ -17,7 +17,7 @@
/** @var SourceLocator */
private $wrappedSourceLocator;

/** @var Reflection[] indexed by reflector key and identifier cache key */
/** @var (Reflection|null)[] indexed by reflector key and identifier cache key */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is not supported by other tools (eg. PHPCS), please don't use it.

@@ -30,6 +30,7 @@ public function __invoke(array $stringTypes, Context $context) : array
$resolvedTypes[] = $this->typeResolver->resolve($stringType, $context);
}

/** @var Type[] */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doccomment should be on line 27 and contain variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did one of those for-the-typechecker things where I told it that the array only gets non-nullable objects in the foreach

@Ocramius
Copy link
Member

Note: this is to be taken over by the @Roave folks, as I just asked @muglug to open the PR with his current patch

@@ -685,8 +690,8 @@ function (ReflectionClass $trait) use ($filter) {

return array_filter(
$this->cachedProperties,
function (ReflectionProperty $property) use ($filter) {
return $filter & $property->getModifiers();
function (ReflectionProperty $property) use ($filter) : bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be founded with CS :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's difficult. There are no annotations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're basically missing a mixed return type (in the language) in order to have CS here too...

@prisis
Copy link
Contributor

prisis commented May 17, 2018

Why did you choose Psalm and not phpstan?

@muglug
Copy link
Contributor Author

muglug commented May 17, 2018

@asgrim
Copy link
Member

asgrim commented May 17, 2018

@prisis we had phpstan before, but it's incompatible with PhpParser 4, psalm is a great tool also 👍

@kukulich
Copy link
Collaborator

PHPStan will return :) It is disabled only temporarily 31129a7

@muglug
Copy link
Contributor Author

muglug commented May 17, 2018

Also because of https://twitter.com/Ocramius/status/994684609928540161

But now PHPStan supports 4.0 in dev-master, this PR may well be extraneous.

@Ocramius
Copy link
Member

this PR may well be extraneous.

No, I think this PR is a good fit. This is an extremely clean library (not the best architecture, but we put some effort in it), and it values types over everything else, so having multiple type checkers is beneficial both for the library and for the authors of the type checkers.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! The comments in the review are just questions, but I'm fine with 🚢 -ing this as-is.

@@ -156,6 +156,7 @@ public function getClosureNodes() : ?array
$nodeTraverser->addVisitor($nodeVisitor);
$nodeTraverser->traverse($ast);

/** @var array $closureNodes */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Node[]?

@@ -47,6 +47,8 @@
*
* @throws \InvalidArgumentException
* @throws \ReflectionException
*
* @psalm-suppress DocblockTypeContradiction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding custom annotations is a bit risky due to various annotation parsers. @muglug what do you think about these? Is this kind of stuff something that psalm.xml can handle at all?

@@ -685,8 +690,8 @@ function (ReflectionClass $trait) use ($filter) {

return array_filter(
$this->cachedProperties,
function (ReflectionProperty $property) use ($filter) {
return $filter & $property->getModifiers();
function (ReflectionProperty $property) use ($filter) : bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're basically missing a mixed return type (in the language) in order to have CS here too...

@Ocramius Ocramius self-assigned this May 17, 2018
@Ocramius Ocramius added this to the 3.0.0 milestone May 17, 2018
@Ocramius
Copy link
Member

🚢

@Ocramius Ocramius merged commit 2b8a18a into Roave:master May 26, 2018
@Ocramius Ocramius changed the title Add Psalm to build and fix issues found Add vimeo/psalm to the build and fixed detected static analysis issues that were detected by it May 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants