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

#213 implemented Assert::positiveInteger() to have psalm positive-int assertions #214

Merged
merged 8 commits into from
Mar 7, 2021

Conversation

Ocramius
Copy link
Contributor

@Ocramius Ocramius commented Aug 28, 2020

Fixes #213

Needs:

Fixes #213
Fixes #214
Fixes #97
Fixes #229

@Ocramius
Copy link
Contributor Author

No, style-ci, that stuff is not valid/to be fixed :P

src/Assert.php Show resolved Hide resolved
Copy link
Collaborator

@BackEndTea BackEndTea left a comment

Choose a reason for hiding this comment

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

Got one minor comment.

I can see the use case for this assertion, especially with prices etc, where 0 would also not be allowed.

src/Assert.php Outdated Show resolved Hide resolved
Ocramius added a commit to Ocramius/assert-1 that referenced this pull request Aug 31, 2020
…ToString()` for `Assert::positiveInteger()` failures

Ref: webmozarts#214 (comment)
@Ocramius
Copy link
Contributor Author

CI failure unrelated

@Ocramius
Copy link
Contributor Author

@BackEndTea can we ship this?

@Ocramius
Copy link
Contributor Author

Ocramius commented Nov 6, 2020

@BackEndTea sorry to page again - can I somehow help here? Can I perhaps help by introducing release automation?

@Ocramius
Copy link
Contributor Author

@BackEndTea sorry, didn't see that you pushed to my fork - currently rebasing to get this merged

Ocramius added a commit to Ocramius/assert-1 that referenced this pull request Jan 19, 2021
…ToString()` for `Assert::positiveInteger()` failures

Ref: webmozarts#214 (comment)
@Ocramius Ocramius force-pushed the feature/#213-assert-positive-int branch from 727bbbc to 864876c Compare January 19, 2021 12:44
@Ocramius
Copy link
Contributor Author

Ocramius commented Jan 19, 2021

@zerkms you probably want to check this one. As discussed with @muglug, the entire @mixin thing seemed like a good idea, but is really hacks upon hacks upon hacks.

I therefore changed your code generator to generate a trait instead (since the package is now using ^7.2 || ^8.0)

@Ocramius Ocramius force-pushed the feature/#213-assert-positive-int branch 5 times, most recently from 349e997 to da39c25 Compare January 19, 2021 15:35
@Ocramius
Copy link
Contributor Author

Note to maintainers: please do not squash this!

Copy link
Contributor

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Im super impressed. Great work.

Thank you for the rebase.

I see that psalm complains. The error seam valid. Is it related to your PR?

tests/AssertTest.php Show resolved Hide resolved
@Ocramius
Copy link
Contributor Author

I see that psalm complains. The error seam valid. Is it related to your PR?

That would be the first TODO that is left above - I'm waiting for a merge (if applicable) and release of vimeo/psalm#5050.

@zerkms
Copy link
Contributor

zerkms commented Jan 19, 2021

@zerkms you probably want to check this one. As discussed with @muglug, the entire @mixin thing seemed like a good idea, but is really hacks upon hacks upon hacks.

I therefore changed your code generator to generate a trait instead (since the package is now using ^7.2 || ^8.0)

@Ocramius I initially was pro-trait/base-class, so it definitely looks good to me :-)

…ToString()` for `Assert::positiveInteger()` failures

Ref: webmozarts#214 (comment)
…Assert` type inference mechanism

Ref: https://symfony-devs.slack.com/archives/C8SFXTD2M/p1611064766060600

Quoting:

```
ocramius  2:59 PM
can anyone help me tackle down vimeo/psalm#4381 ?
Mostly trying to figure out whether the assertions are being read differently for @mixin and concrete instances 😐

muglug  3:18 PM
mixins are a massive hack, both whenever they're used but also in Psalm
anything that relies on magic methods to work is going to be more flaky, so I'd encourage you to think of a non-mixin approach if at all possible

ocramius  3:19 PM
yeah, I'm thinking of doing that indeed, just unsure about approach yet 😐
can't they somehow be unified with traits though?
they're the same thing, no?

muglug  3:22 PM
if they were, you'd just use a trait!

ocramius  3:22 PM
ack, gonna actually try that approach for webmozart/assert then 🙂

muglug  3:24 PM
with mixins the method that's actually being called is either __call or __callStatic, whereas with traits it's still that exact method

ocramius  3:24 PM
yes, I was just wondering if it could import the method as if it was a trait (at type level)
that would squash out *a lot* of code, but it's also true that a mixin does not have a trait definition
I think it makes sense to use the language feature for this 🙂
```

The `@mixin` support in `vimeo/psalm` is a massive hack, which also requires other tooling to increase complexity
in the static analysis parsing capabilities. In order to reduce that complexity, we instead rely on `Assert`
importing `Mixin` as a trait, which is much simpler and much more stable long-term.

While this indeed leads to `Mixin` being changed from an `interface` to a `trait`, that is not really a BC
break, as `Mixin` was explicitly documented to be used only as a type system aid, and not as an usable
symbol.
…ural()` doing the same thing

Note: we refined the assertion on `Assert::natural()` to correctly restrict to `positive-int|0`,
but we had to remove some minor test on `Assert::allNaturalNumber()` due to `@psalm-assert iterable<positive-int|0>`
not yet working in upstream.

See vimeo/psalm#5052
… broken as per vimeo/psalm#5310)

While there is no guarantee that `vimeo/psalm:4.6.3` will fix the issue, we know for sure that
`vimeo/psalm:4.6.2` is broken, as per vimeo/psalm#5310, and we cannot
therefore rely on its static analysis there until upstream issue is fixed.

Meanwhile, this allows for installation of `webmozart/assert` with `vimeo/psalm:4.6.1` and `vimeo/psalm:>4.6.2`,
hoping for a brighter future.
@Ocramius Ocramius force-pushed the feature/#213-assert-positive-int branch from da39c25 to 6d7d868 Compare March 2, 2021 15:23
@Ocramius
Copy link
Contributor Author

Ocramius commented Mar 2, 2021

@BackEndTea @Nyholm I've now rebased and everything looks OK.

Only failure seems to be with scrutinizer-ci, which doesn't seem to accept coverage anymore:


#!/usr/bin/env php
Uploading code coverage for repository "g/webmozarts/assert" and revision "8f1ec4c49eea2fec54bb8ec563bd8d73ac0a3eb9"... Failed
{
    "message": "Not found",
    "description": "The requested page was not found, or you have no access to view it."
}

Meanwhile, I reported vimeo/psalm#5310 and excluded vimeo/psalm:4.6.2 from compatibility, hoping it will somehow be fixed (although optimistically, locking locally in ci/composer.lock is an acceptable solution for us for now).

If you have time, let's roll with this, as it fixes a gazillion issues, and could really need a new release \o/

Copy link
Contributor

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

A gazillion issues fixed in one PR? This is great.

I've reviewed the code and I'm happy with merging.

Thank you Marco

@Ocramius
Copy link
Contributor Author

Ocramius commented Mar 2, 2021

@Nyholm since the last review, the only change is 6d7d868 BTW (the rest is rebase noise)

@Ocramius
Copy link
Contributor Author

Ocramius commented Mar 3, 2021

@Nyholm was the merge held off then? 🤔

@Nyholm
Copy link
Contributor

Nyholm commented Mar 3, 2021

I wanted to wait a day or two for @BackEndTea to have a chance to review it again.

@Nyholm
Copy link
Contributor

Nyholm commented Mar 7, 2021

Thank you

@Nyholm Nyholm merged commit 6747ed2 into webmozarts:master Mar 7, 2021
@Ocramius Ocramius deleted the feature/#213-assert-positive-int branch March 8, 2021 13:40
@Ocramius
Copy link
Contributor Author

Ocramius commented Mar 8, 2021

@Nyholm @BackEndTea thank you! Eager to try it out, lemme know if there's anything I can help with to get it released.

If releases are currently onerous, I can help setting up automation, like I did for https://github.com/webmozarts/glob

@Nyholm
Copy link
Contributor

Nyholm commented Mar 8, 2021

I've seen this https://github.com/webmozarts/glob/blob/4.4.x/.github/workflows/release-on-milestone-closed.yml

My mind has not matured for this yet. =)

I'll get there eventually.

@Nyholm
Copy link
Contributor

Nyholm commented Mar 9, 2021

Note to maintainers: please do not squash this!

Oh no!

All of yesterday, I had this feeling that I've read this note somewhere but I could not remember where. I remembered.

Sorry, I did squash the commits.


Unrelated, Im preparing the release now.

@Ocramius
Copy link
Contributor Author

Ocramius commented Mar 9, 2021

Heh, I mostly did say that because, if you look at the patch history, the commits are made individually, each with a decent commit message, useful to pinpoint regressions :(

Still happy about a release though, but as a good habit, squashing is the exception, not the norm :P

@Nyholm
Copy link
Contributor

Nyholm commented Mar 9, 2021

If one is making commits like you did in this PR, I can be okey with not squashing. But that is rarely what I see, and I've never done it myself. =)

I like the clean look of the history when one squash the commits.

Screenshot 2021-03-09 at 12 11 35


Anyhow, I appreciate all the work you've put into making this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants