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

More static analysis (Psalm related changes) #43

Closed
wants to merge 9 commits into from

Conversation

alexeyshockov
Copy link
Contributor

Fixes #41

@alexeyshockov alexeyshockov changed the title Psalm config tuned, more strict types in the code More static analysis (Psalm related changes) Jun 29, 2020
"php-coveralls/php-coveralls": "^2.2",
"vimeo/psalm": "^3.5"
"vimeo/psalm": "3.14.*"
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 fixed Psalm version here, to have more consistent builds over time. It should be upgraded sometimes, of course, but having stable builds is more important (as you correctly pointed).

Copy link

Choose a reason for hiding this comment

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

I think it might be worth going further and constraining to a specific point release of Psalm (e.g. current release 3.14.2. I don't think it's very unusual for psalm patch level releases to detect errors that the previous release wouldn't have detected.

If we don't constrain it to the patch then someone making a PR may have the build fail because of an issue in code they haven't touched and shouldn't be expected to fix.

@alexeyshockov
Copy link
Contributor Author

@BenMorel, could you take a look at the coverage report? It says that the coverage decreased dramatically for NativeCalculator, but there are only few lines changed there...

src/BigDecimal.php Outdated Show resolved Hide resolved
src/BigDecimal.php Outdated Show resolved Hide resolved
@BenMorel
Copy link
Member

@alexeyshockov regarding coverage, I've already contacted Coveralls for similar problems, and am waiting for their response. I wouldn't be too picky about coverage right now.

@@ -291,6 +293,7 @@ public function exactlyDividedBy($that) : BigDecimal

[, $b] = $this->scaleValues($this, $that);

/** @var numeric-string $d */
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use @psalm-var here as well?

Copy link

Choose a reason for hiding this comment

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

@BenMorel It would be yes. Psalm still passes.

@@ -182,7 +183,7 @@ private static function floatToString(float $float) : string
*
* @psalm-pure
*/
protected static function create(... $args) : BigNumber
protected static function create(... $args) : self
Copy link
Member

Choose a reason for hiding this comment

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

Did you change it to return self as a matter of coding style, or does Psalm complain for some reason when returning BigNumber?

Copy link

Choose a reason for hiding this comment

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

Psalm is fine with either. As far as I know it should treat them as synonyms.

@BenMorel
Copy link
Member

@alexeyshockov What's the point of using numeric-string everywhere, exactly? Does Psalm complain when using a generic string with GMP or BCMath?

According to the docs, numeric-string represents any string that passes the is_numeric() check, which is not restrictive enough for this project anyway, as we're only dealing with strings of digits with optional minus sign, while is_numeric() accepts other formats, like exponential notation.

@BenMorel
Copy link
Member

Hi @alexeyshockov, any update on the points above?

@bdsl
Copy link

bdsl commented Aug 27, 2020

@BenMorel I tried a search and replace of 'numeric-string' to 'string' to see if Psalm complains. It does, 23 times.

According to psalm the bc functions need numeric-strings, as do the php *, +, - operators. I think it's fine to use it. It's not as restrictive as we might like but that's unavoidable. The string type is even less restrictive. Type systems rarely enforce all necessary restrictions.

@BenMorel
Copy link
Member

BenMorel commented Sep 9, 2020

@bdsl Thank you for your comments.
@alexeyshockov Ping!

@BenMorel
Copy link
Member

I upgraded Psalm to 4.1 and fixed all the Psalm issues in cbdd960.

@alexeyshockov I did not use numeric-string anywhere, I preferred to suppress the error in BcMathCalculator, rather than letting numeric-string bubble up and create > 100 errors everywhere else in the code.

We have a strong requirement on the format of the internal numeric strings used in brick/math, something that cannot be enforced strictly enough by Psalm anyway, so I see little value in adding @psalm- specific annotations everywhere for something that brings next to no value.

Please feel free to open a new PR if you see something that can be improved!

@BenMorel BenMorel closed this Oct 30, 2020
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.

New Psalm issues
3 participants