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

Introduce Static Analysis Checking System #90

Merged
merged 8 commits into from
May 23, 2021

Conversation

AlexandruGG
Copy link
Collaborator

@AlexandruGG AlexandruGG commented May 21, 2021

This PR aims to kickstart improvements to static analysis
Follows #89.

Overall

  • Increase Psalm strictness & add baseline
  • Introduce tests/static-analysis
  • Fixing some issues where applicable

Checks added

  • fromFile
  • fromResource
  • fromString

psalm.xml Show resolved Hide resolved
@drupol
Copy link
Collaborator

drupol commented May 21, 2021

It seems that ::fromFile() is a new constructor.

I've always been reluctant to add it because I haven't found a proper way to do the fclose() at the end. Do you have a clue??

I'm not so keen on leaving the resource open without closing them.

@AlexandruGG
Copy link
Collaborator Author

It seems that ::fromFile() is a new constructor.

I've always been reluctant to add it because I haven't found a proper way to do the fclose() at the end. Do you have a clue??

I'm not so keen on leaving the resource open without closing them.

Challenge accepted! 😄

Let me know if this looks good: e000805

@AlexandruGG
Copy link
Collaborator Author

It seems that ::fromFile() is a new constructor.
I've always been reluctant to add it because I haven't found a proper way to do the fclose() at the end. Do you have a clue??
I'm not so keen on leaving the resource open without closing them.

Challenge accepted! 😄

Let me know if this looks good: e000805

I realised that this iterator is also used in fromResource, where the user already provides a resource. We might not want to close it in that case as it should be up to the caller, so I'm thinking to add a boolean parameter to ResourceIterator with default value false that should be used to check if the resource should be closed. Does that sound good?

drupol
drupol previously approved these changes May 22, 2021
Copy link
Collaborator

@drupol drupol left a comment

Choose a reason for hiding this comment

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

I realised that this iterator is also used in fromResource, where the user already provides a resource. We might not want to close it in that case as it should be up to the caller, so I'm thinking to add a boolean parameter to ResourceIterator with default value false that should be used to check if the resource should be closed. Does that sound good?

This is exactly why it is done like that, I let the user close its resource.

In overall, I'm ok with the pull request, feel free to submit it!

spec/loophp/collection/CollectionSpec.php Show resolved Hide resolved
@AlexandruGG
Copy link
Collaborator Author

I realised that this iterator is also used in fromResource, where the user already provides a resource. We might not want to close it in that case as it should be up to the caller, so I'm thinking to add a boolean parameter to ResourceIterator with default value false that should be used to check if the resource should be closed. Does that sound good?

This is exactly why it is done like that, I let the user close it's resource.

In overall, I'm ok with the pull request, feel free to submit it!

Ok so we don't want ResourceIterator to always close the resource. I will add that parameter to ensure that we only close it in fromFile and not in fromResource.

Also, I'll add the static analysis check for fromResource and after that it'll be ready for review :)

@drupol
Copy link
Collaborator

drupol commented May 22, 2021

Maybe a new extra parameter to ResourceIterator ?

@@ -415,15 +415,14 @@ public static function fromIterable(iterable $iterable): self

/**
* @param resource $resource
*
* @return self<int, string>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@drupol I see a mix of annotations in this project, but I'm not sure why that is. Should we use the psalm ones or the "normal" ones everywhere?

A. @param, @return, @template
B. @psalm-param, @psalm-return, @psalm-template

For the analysers it doesn't matter because they support both. And in an IDE like PHPStorm / IntelliJ both are properly highlighted.

I personally favour A just because of a couple small reasons:

  • less characters to write. And easier to mentally parse when reading 😄
  • doesn't tie the code to a specific developer tool (though, again, doesn't really matter because both are supported)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also on my Todo list! Option A for the win :)

@AlexandruGG AlexandruGG changed the title Static analysis improvements Introduce Static Analysis Checking System May 23, 2021
@AlexandruGG AlexandruGG marked this pull request as ready for review May 23, 2021 10:58
@drupol drupol enabled auto-merge (squash) May 23, 2021 15:12
Copy link
Collaborator

@drupol drupol left a comment

Choose a reason for hiding this comment

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

Excellent!

@drupol drupol merged commit 5f1caeb into loophp:master May 23, 2021
@AlexandruGG AlexandruGG deleted the static-analysis-improvements branch May 23, 2021 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants