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
NEW Use composer 2 #62
NEW Use composer 2 #62
Conversation
7c4dade
to
aeb9425
Compare
@spekulatius are you OK with us tagging a new major (v3) to support composer v2? It's required for PHP 8.1 support. |
aeb9425
to
f6730af
Compare
@@ -113,7 +101,7 @@ public function onAfterBuild() | |||
// Mock COMPOSER_HOME if it's not defined already. Composer requires one of the two to be set. | |||
if (!Environment::getEnv('COMPOSER_HOME')) { | |||
$home = Environment::getEnv('HOME'); | |||
if (!$home || !is_dir($home) || !is_writable($home)) { | |||
if (!$home || !is_dir($home ?? '') || !is_writable($home ?? '')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!$home
should short circuit on null, so the null coalescing operator isn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@@ -53,7 +51,7 @@ public function getPackages(array $allowedTypes = null) | |||
$repository = $this->getRepository(); | |||
foreach ($repository->getPackages() as $package) { | |||
// Filter out packages that are not "allowed types" | |||
if (is_array($allowedTypes) && !in_array($package->getType(), $allowedTypes)) { | |||
if (is_array($allowedTypes) && !in_array($package->getType(), $allowedTypes ?? [])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if is_array($allowedTypes)
is false, then we won't get to the in_array()
call, so the null coalescing operator isn't necessary.
@@ -130,7 +118,7 @@ public function onAfterBuild() | |||
$this->setComposer($composer); | |||
|
|||
if ($originalDir !== BASE_PATH) { | |||
chdir($originalDir); | |||
chdir($originalDir ?? ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$originalDir
is either a string or false, never null.
chdir($originalDir ?? ''); | |
chdir($originalDir ?: ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
@@ -117,7 +116,7 @@ protected function findLatestPackage( | |||
} | |||
|
|||
$targetVersion = null; | |||
if (0 === strpos($installedVersion, 'dev-')) { | |||
if (0 === strpos($installedVersion ?? '', 'dev-')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting here for posterity:
$installedVersion
comes from PackageInterface::getPrettyVersion()
. This is strongly typed from 2.3.0 to return a string - but not in 2.0.0.
*/ | ||
protected function getInstalledConstraint(BaseRepository $repository, $packageName) | ||
protected function getInstalledConstraint(InstalledRepository $repository, string $packageName): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link::getPrettyConstraint()
can return null in composer 2.0.0
protected function getInstalledConstraint(InstalledRepository $repository, string $packageName): string | |
protected function getInstalledConstraint(InstalledRepository $repository, string $packageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added $link->getPrettyConstraint() ?? ''
so that it's always a string
* | ||
* @param BaseRepository $repository | ||
* @param string $packageName | ||
* @return string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing the PHPDoc typings here (and, I've just noticed, elsewhere as well)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is going to be a new major, and I've switched to using proper method type hints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention that anywhere we have type hints we should remove phpdoc typings? I'm generally in favour of that wherever the phpdoc doesn't provide additional context such as here - but in that case we should probably do it as a blanket action everywhere, yes?
I think we should probably leave the phpdocs alone for this PR, since making graphql4 strongly typed is already another load of work that needs to be done, and it should be done consistently (either leaving/updating them or removing them).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everywhere, yes?
No. Most of Silverstripe was made for PHP 5, is dynamically typed and relys on docblocks for typehinting.
There are plenty of example where there are strongly typed methods with docblocks, though that was done when PHP 5.6 was still supported. It is no longer supported. However removing the old docblocks on a case by case basis right now is very low priority. I'm sure we'll do an automated bulk cleanup at some point in the future.
Where new API is created (which is what is happening here, this is for a new major after all), I'm using strong typing and not using docblock types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had meant "everywhere" as in "everywhere in this module where new API is provided" so I think we're on the same page there.
Also for some reason when I made that comment my brain was telling me this was on silverstripe/graphql which it definitely isn't. 😅Sorry about that. Yup I'm okay with this.
f6730af
to
dcd4d1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran locally, worked great. For any private repositories, a short line is added to the messages for the queued job as below, and that repository doesn't have its "latest" or "available" columns populated in the report.
[DEBUG] Could not authenticate against github.com
LGTM. I don't have access to merge this, though.
@spekulatius Just to let you know we're going to merge this and tag a new major, let us know if this is an issue. If we haven't heard from you within a few days we'll assume this is ok and go ahead with it. |
Sounds good to me @emteknetnz |
Issue silverstripe/silverstripe-framework#10250
Switch from composer 1 to composer 2, also add the
??
operator to a few native function calls to ensure null values aren't passed in for PHP 8.1 compatibilityCreate 3 + 3.0 branches and tag 3.0.0 when merged
Required for silverstripe/recipe-reporting-tools#26