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

Chore/psalm #228

Merged
merged 22 commits into from
Oct 5, 2023
Merged

Chore/psalm #228

merged 22 commits into from
Oct 5, 2023

Conversation

RobjS
Copy link
Contributor

@RobjS RobjS commented Oct 4, 2023

This PR adds Psalm and modifies the codebase to make it Psalm-compliant in PHP 7.4-8.2 inclusive.

I've modified the CI to explicitly run PHP in each of the PHP versions we run in that environment, because by default Psalm runs in the PHP version inferred from the composer platform (currently 7.4). That would mean, even though we run CI in 4 different PHP versions, Psalm would be running against 7.4 in all 4 pipelines. Now, it will run once against 7.4 (as part of the standard script/test run), but then also run against the PHP version set for that pipeline.

Resolves #222

  • Includes tests (if new features are introduced) - N/A
  • Commit message includes link to the ticket/issue
  • Changelog updated
  • PR open against dxw's Homebrew Tap to point the Whippet formula to the new version number - N/A

RobjS added 9 commits October 3, 2023 16:56
A lot of these are false positives, because Psalm doesn't fully
understand the way Whippet is structured.
These are definitely used, Psalm just doesn't understand how.
These are definitely used, it's not clear to me why Psalm can't see
that.
It should be passing an array of the command and options, no a single
string.
There is no namespaced version of the Exception class, so this should be
referencing the top-level version.
Otherwise:

a) There's a chance (though not following the current logic) it could be
references when no value is set;
b) Psalm complains about dynamic property
RobjS added 13 commits October 4, 2023 14:53
This is defined in the bin file.
`$this->plugin_dir` will have been defined by the class using this trait
by the time this method is used.
There is no need for the `die()`, as an `E_USER_ERROR` will stop
execution of the script anyway.
From PHP 8.1 up, internal methods like `__toString()` that can be
over-ridden require the over-riding method to declare a compatible
return type. Failure to do so will result in a deprecation notice.

However, currently, if we declare a return type on this method, it
results in the Kahlan tests failing, as the `__toString()` method Kahlan
generates on its double for this class does not have a return type, so
is viewed as incompatible with the class it's trying to double.

Declaring the ReturnTypeWillChange attribute prevents the deprecation
notice being issued, and stops Psalm complaining about it.

See: https://php.watch/versions/8.1/ReturnTypeWillChange
By default, Psalm will infer the PHP version it should be running
against from the composer platform.

We want to keep that composer platform at 7.4 for now, but for advance
warning of potential PHP8 issues we also want to run Psalm against PHP8
versions, so we can use the `--php-version` option to specifically run
Psalm against those PHP versions.
Before: we were trying to loop through `$this->plugins_locked` as if it
was an array (as previously we'd been using `foreach` with key/value
pairs). However, it's actually an object, and foreach-ing an object
produces a key-value array of the visible properties of that object.

Now: we use get_object_vars to get the visible properties as an array,
then use array_keys on that.
@@ -81,7 +81,7 @@ public function clone_no_checkout($repository)
return false;
}

$this->run_command("mv {$tmpdir}/.git {$this->repo_path}");
$this->run_command(['mv', $tmpdir . '/.git', $this->repo_path]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking comment: there's a typo in the commit message here s/no/not/g

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! Fixed in a rebase I'll push post-approval.

Copy link
Contributor

@snim2 snim2 left a comment

Choose a reason for hiding this comment

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

This looks good. The return type thing is quite unfortunate though, and I think we should probably have a PHP8.x issue that lists things like this that need tidying up.

@RobjS
Copy link
Contributor Author

RobjS commented Oct 4, 2023

This looks good. The return type thing is quite unfortunate though, and I think we should probably have a PHP8.x issue that lists things like this that need tidying up.

I've opened an issue for that here: #229

@RobjS
Copy link
Contributor Author

RobjS commented Oct 5, 2023

@snim2 This is ready for another look now.

@RobjS RobjS merged commit 4cec082 into main Oct 5, 2023
@RobjS RobjS deleted the chore/psalm branch October 5, 2023 14:36
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.

Add Psalm
2 participants