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

SA Checks: Methods Starting with "a" #97

Merged
merged 15 commits into from
May 27, 2021

Conversation

AlexandruGG
Copy link
Collaborator

@AlexandruGG AlexandruGG commented May 25, 2021

This PR initially aimed to add to the SA Checks all collection methods starting with the letter "a".

After the discussions and the realisation that more mixed typing usage will be needed, I decided to shorten this to only the static analysis check for all + a few other minor changes.

src/Operation/Append.php Outdated Show resolved Hide resolved
AlexandruGG added 2 commits May 26, 2021 10:31
@AlexandruGG
Copy link
Collaborator Author

@drupol I think what I initially intended to do with these static-analysis checks is proving a bit infeasible 😓 .

I think I didn't realise the flexibility that the operations actually allow because I mostly looked at the type hints, which are more restrictive at the moment than what the library allows you to do. For example Associateable suggests that you will get back the same TKey, T but actually the types can be completely different depending on what transformation you have in the callbacks.

In addition, most of the examples in the documentation are with collections of a single type.

I think that in order to allow for usage as intended, with a lot of flexibility, things need to be a bit more loosely-typed. That's probably one of the reasons why the Laravel Collections typings are a lot less specific, i.e. more usage of mixed and callable but without specifying the types for keys and values. I'm not a fan of it but I don't see another way if the flexibility is the most important, because the specific type hints are too constraining at the moment.

@drupol
Copy link
Collaborator

drupol commented May 26, 2021

Thanks for being honest, I fully agree and I know that we will loose some typing information because of that flexibility. That's the trade off.

What do you think we should do in order to clean up the types in the library then?

@AlexandruGG
Copy link
Collaborator Author

Thanks for being honest, I fully agree and I know that we will loose some typing information because of that flexibility. That's the trade off.

What do you think we should do in order to clean up the types in the library then?

I think we need to remove some of the template types and allow things to be less specific and mixed.
But at the same time I also would want to keep the existing type hints (they must've taken a lot of work!) and tweak them as needed for the TypedCollection we were discussing in #99.

The best way I see this happening is in parallel: for example let's say I'm adding the static analysis checks for the append method. I would do it for both the regular Collection and the TypedCollection and ensure the static analysis passes for both. That way it would be easier to see the differences between them and ensure everything's working as intended.

@AlexandruGG
Copy link
Collaborator Author

Thanks for being honest, I fully agree and I know that we will loose some typing information because of that flexibility. That's the trade off.
What do you think we should do in order to clean up the types in the library then?

I think we need to remove some of the template types and allow things to be less specific and mixed.
But at the same time I also would want to keep the existing type hints (they must've taken a lot of work!) and tweak them as needed for the TypedCollection we were discussing in #99.

The best way I see this happening is in parallel: for example let's say I'm adding the static analysis checks for the append method. I would do it for both the regular Collection and the TypedCollection and ensure the static analysis passes for both. That way it would be easier to see the differences between them and ensure everything's working as intended.

@drupol what do you think about this approach? If you're okay with it I can start a new PR so you can see what it would look like, and for this PR I would remove most things apart from the all static analysis check and some other minor changes

@drupol
Copy link
Collaborator

drupol commented May 27, 2021

Hi Alex,

Sorry for the delay in my responses. I'm preparing my presentation at AFUP about this library, this is tomorrow: https://event.afup.org/afupday2021-interview-pol-dellaiera/

Regarding your question, yes I agree obviously. As long as we won't use a typed collection, we will have to use mixed a bit everywhere.

Comment on lines +18 to +20
$fact = static fn (float $number): float => (float) Collection::range(1, $number + 1)
->foldLeft($multiplication, 1)
->current();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change was causing a failure in CI and confusing me massively 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah sometimes those tools are extremely frustrating!

@AlexandruGG
Copy link
Collaborator Author

No clue why unit tests are failing on macOS in CI but it's unrelated to the changes here 🤷‍♂️

@AlexandruGG AlexandruGG marked this pull request as ready for review May 27, 2021 18:03
@drupol drupol merged commit 964fa5c into loophp:master May 27, 2021
@drupol
Copy link
Collaborator

drupol commented May 27, 2021

Thanks mate! Now going to reply to your email :)

@AlexandruGG AlexandruGG deleted the static-analysis/a-functions branch May 27, 2021 19:43
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