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

Eliminated Psalm baseline, migrated from webmozart/assert to azjezz/psl #564

Open
wants to merge 7 commits into
base: 4.17.x
Choose a base branch
from

Conversation

Ocramius
Copy link
Collaborator

@Ocramius Ocramius commented Feb 6, 2025

This change is quite massive, and rewrites most of the library so that it is more type-safe, especially when it comes to large JSON structure traversal.

composer/composer:^1 manifest parsing is now gone (not supported anyway, since we depend on composer-runtime-api:^2).

We migrated from webmozart/assert to the incredibly more powerful azjezz/psl dependency, which gives us massive code reduction, and improved type guarantees.

Most tests were also simplified a lot, and some (outdated, due to older PHP versions targeted) are gone.

Test metadata has also been rewritten, and PHPUnit has been tuned to be much stricter.

symfony/console:^7.2.1 has also been bumped, meanwhile.

…z/psl`

This change is quite massive, and rewrites most of the library so that it is
more type-safe, especially when it comes to large JSON structure traversal.

`composer/composer:^1` manifest parsing is now gone (not supported anyway, since
we depend on `composer-runtime-api:^2`).

We migrated from `webmozart/assert` to the incredibly more powerful `azjezz/psl`
dependency, which gives us massive code reduction, and improved type guarantees.

Most tests were also simplified a lot, and some (outdated, due to older PHP
versions targeted) are gone.

Test metadata has also been rewritten, and PHPUnit has been tuned to be much
stricter.

`symfony/console:^7.2.1` has also been bumped, meanwhile.
@Ocramius Ocramius added enhancement dependencies Pull requests that update a dependency file labels Feb 6, 2025
@Ocramius Ocramius added this to the 4.17.0 milestone Feb 6, 2025
@Ocramius Ocramius requested a review from maglnet February 6, 2025 22:46
This leads to some minor tradeoffs between `non-empty-string` vs `string`
declarations, and required us to remove an `@pure` declaration, but is
otherwise a good improvement overall.
This type is relatively safe to keep inside this package (only), and
its only responsibility is really behaving as anti-corruption layer
with `composer.json`, `composer.lock` and `installed.json`, so
this is a good fit.
These are minor dependency upgrades that are well worth having, for
the reduced code complexity in our domain.
@Ocramius Ocramius force-pushed the feature/stricter-types branch from bfa36d6 to 2f87f49 Compare February 6, 2025 23:15
These are slow and wasteful: not worth burning CPUs for no reason.
Many libraries, such as Symfony, don't understand semantic versioning
well, and tend to release software that is incompatible with the next
major version of a dependency (in this case `php`, which does not
follow SemVer).

This kind of botched architecture by Symfony leads to dependencies having
broken behavior in oldstable releases.

This is effectively a choice by the upstream maintainer (Symfony) to
leave this sort of problem to the consumer (in this case, us), who then
has to restrict ranges more aggressively.

In this case, the failures are due to transitive dependencies leading to
symfony, so introducing a `conflict` worsens the situation for our own
consumers/
@Ocramius
Copy link
Collaborator Author

Ocramius commented Feb 6, 2025

@maglnet since I'm touching a lot of the project, you might want to take a glance here, especially to see how I'm ripping out pieces to use azjezz/psl instead, which is a fabulous library :D

$fileName = realpath($configFileArgument);
if ($fileName === false) {
$fileName = Filesystem\canonicalize($configFileArgument);
if ($fileName === null) {
throw new InvalidArgumentException(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be listed in the @throws docblock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Possibly: I added @throws in an age when the IDE was really pedantic about it.

I don't believe them to be as important anymore, but if you believe so, we can tweak SA tools to check these

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should either use the tag or not. I'm happy with the tags going away / being removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd say that they are relevant for things where we explicitly also test for them

Comment on lines 62 to 83
$fileContent = file_get_contents(__DIR__ . '/../../../data/config.dist.json');
$this->assertNotFalse($fileContent);

$optionsFromFile = new Options(
json_decode($fileContent, true),
);
$optionsFromFile = new Options([
'symbol-whitelist' => [],
'php-core-extensions' => [
'Core',
'date',
'json',
'hash',
'pcre',
'Phar',
'Reflection',
'SPL',
'random',
'standard',
],
'scan-files' => [],
]);

$this->assertEquals($options, $optionsFromFile);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

$fileContent is no longer used in this test. We are now comparing new Options() with new Options( $some_fixed_content ). The file isn't used at all here any longer. Perhaps this test should be renamed or rewritten?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, renaming is a good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants