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

Cli command classes #5858

Merged
merged 22 commits into from
Jun 1, 2021
Merged

Cli command classes #5858

merged 22 commits into from
Jun 1, 2021

Conversation

weirdan
Copy link
Collaborator

@weirdan weirdan commented May 30, 2021

Over the years Psalm's entrypoints have grown quite large. This PR aims to solve it by moving the entrypoint code to their own classes.

Overview of changes:

  • src/*.php entrypoints moved to corresponding classes in src/Psalm/Internal/Cli folder
  • Global functions in \Psalm namespace deprecated and moved to Psalm\Internal\CliUtils class
  • Psalm\Internal\Cli\Psalm::run() (originally src/psalm.php) split into multiple methods
  • Psalm\Internal\Cli\Psalter::run() (originally src/psalter.php) split into multiple methods

@weirdan
Copy link
Collaborator Author

weirdan commented May 30, 2021

The remaining CI issue is somewhat puzzling. It's only reproducible with --threads=1 (which is implicit on AppVeyor).

There seems to be an existing bug where multiple relative paths may reference the same file, ending up in the same file being scanned several times.

@weirdan weirdan marked this pull request as ready for review May 31, 2021 00:05
@weirdan weirdan requested review from muglug and orklah May 31, 2021 00:05
@orklah
Copy link
Collaborator

orklah commented May 31, 2021

There's a lot of code being repeated (sometimes with mistakes) between entry points, for example, the php-version fixed here #5855.

I see you introduced a initPhpVersion on Psalm entry point. Maybe this method should be extracted into CliUtils class and used by everyone?

@weirdan
Copy link
Collaborator Author

weirdan commented May 31, 2021

@orklah I'd like to defer that to subsequent, more focused, PRs. While I certainly agree with the sentiment, this one is quite big already. Here I aimed for bug-for-bug compatibility, to ease the transition.

@orklah
Copy link
Collaborator

orklah commented May 31, 2021

Well, seems weird you refactored things in methods only in Psalm entrypoint and not on Psalter then.

But apart from that, the PR seems great :)

@weirdan
Copy link
Collaborator Author

weirdan commented May 31, 2021

Well, seems weird you refactored things in methods only in Psalm entrypoint and not on Psalter then.

Initially I did not intend to do that in this PR, but Psalm was complaining about ComplexMethod 😄. So once it stopped doing that I deemed the PR good enough.

@orklah
Copy link
Collaborator

orklah commented May 31, 2021

Can relate to that :D

@muglug muglug merged commit 448534f into vimeo:master Jun 1, 2021
@muglug
Copy link
Collaborator

muglug commented Jun 1, 2021

Thanks!

Initially I did not intend to do that in this PR, but Psalm was complaining about ComplexMethod 😄. So once it stopped doing that I deemed the PR good enough.

Is this annoying or is it good?

@weirdan
Copy link
Collaborator Author

weirdan commented Jun 1, 2021

Is this annoying or is it good?

It's ok, but I did not expect that - the method was no more complex than the closure originally found in src/psalm.php, but Psalm did not flag that closure. Also the measure of complexity used is not very intuitive. IIRC, the most complexity reduction came from extracting code like this:

psalm/src/psalm.php

Lines 218 to 236 in 38c452a

if (array_key_exists('help', $options)) {
$options['h'] = false;
}
if (array_key_exists('version', $options)) {
$options['v'] = false;
}
if (array_key_exists('init', $options)) {
$options['i'] = false;
}
if (array_key_exists('monochrome', $options)) {
$options['m'] = false;
}
if (isset($options['config'])) {
$options['c'] = $options['config'];
}

Arguably this does not look the most complex part of that method.

@weirdan weirdan mentioned this pull request Jun 6, 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.

3 participants