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 psalm assertions #282

Closed
wants to merge 3 commits into from
Closed

Conversation

muglug
Copy link
Contributor

@muglug muglug commented Jun 9, 2019

These allow anyone using Psalm (or any other tool that understands its annotations) to understand the effect of beberlei/assert calls in their code.

Similar to sebastianbergmann/phpunit#3708

@@ -1834,6 +1920,8 @@ public static function e164($value, $message = null, $propertyPath = null)
* @param string|null $message
* @param string|null $propertyPath
*
* @psalm-assert non-empty-countable $value
Copy link

Choose a reason for hiding this comment

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

This gives me

PHP Fatal error:  Uncaught Psalm\Exception\TypeParseTreeException: no hyphens allowed in projectdir/vendor/vimeo/psalm/src/Psalm/Type/Atomic.php:187
Stack trace:
#0 projectdir/vendor/vimeo/psalm/src/Psalm/Type.php(129): Psalm\Type\Atomic::create('Assert\\non-empt...', NULL, Array)
#1 projectdir/vendor/vimeo/psalm/src/Psalm/Type.php(102): Psalm\Type::parseTokens(Array, NULL, Array)
#2 projectdir/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php(1123): Psalm\Type::parseString('Assert\\non-empt...', NULL, Array)
#3 projectdir/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php(205): Psalm\Type\Reconciler::reconcileTypes('Assert\\non-empt...', Object(Psalm\Type\Union), '$value', Object(Psalm\Internal\Analyzer\StatementsAnalyzer), false, Array, Object(Psalm\CodeLocation), Array, 0)
#4 projectdir/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer. in projectdir/vendor/vimeo/psalm/src/Psalm/Type/Atomic.php on line 187

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry - fixed in 7a14e87 - will release tonight

Copy link

Choose a reason for hiding this comment

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

Don't be sorry ;) Thanks

@rquadling
Copy link
Contributor

What's the benefit these annotations? Who will maintain them when we add new assertions? What's the consequences of not adding them? What's the consequence/diagnostics of an incorrect one (say we edit the method signature or behaviour)?

@muglug
Copy link
Contributor Author

muglug commented Jun 11, 2019

What's the benefit these annotations?

The annotations allow Psalm to understand what effect these assertions when it analyses these calls during type inference.

What’s the consequence of not adding them?

A mild inconvenience for people who rely on this library and Psalm.

What's the consequence/diagnostics of an incorrect one (say we edit the method signature or behaviour)?

The few annotations here are relatively simple - if you were to change the assertion operation drastically (e.g. returning false vs throwing an error) the assertions would have to be changed, but that would constitute a very breaking change for this library anyway.

@rquadling
Copy link
Contributor

Psalm vs PHPStan? Do any IDEs support Psalm?

@muglug
Copy link
Contributor Author

muglug commented Jun 16, 2019

Psalm vs PHPStan? Do any IDEs support Psalm?

Psalm runs a language server that is compatible with most IDEs: https://psalm.dev/docs/running_psalm/language_server/

There's also this ticket: https://youtrack.jetbrains.com/issue/WI-45248

PHPStan doesn't support any docblock assertion syntax, but it may in the future.

@emilioastarita
Copy link

👍 These annotations could be really useful for us. We use Assert extensively and we added psalm recently to our pipeline.

@rquadling
Copy link
Contributor

Can the merge conflict be resolved (rebasing onto the latest master too please).

@orklah
Copy link

orklah commented Jan 6, 2020

It would be cool to have those assertions. I intended to use this package to validate my input to be fully typed in psalm but it doesn't help without those.

@githoober
Copy link

Checking again today. Is there anything we can do to have this PR merged?

@githoober
Copy link

@rquadling this branch does not seem to have conflicts with the master. Could you merge it?

@magnetik
Copy link

It now have a conflict, do you mind rebasing it?

@beberlei beberlei mentioned this pull request Nov 13, 2020
@Wirone
Copy link
Contributor

Wirone commented Dec 3, 2020

@muglug maybe you can close this issue since @beberlei rebased your work and merged it in #305 🙂

@beberlei beberlei closed this Dec 3, 2020
@beberlei beberlei reopened this Dec 3, 2020
@beberlei
Copy link
Owner

Merged in #305

@beberlei beberlei closed this Apr 18, 2021
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

9 participants