Skip to content

Commit d6fa534

Browse files
authored
fix: apply packagist changes to GithubStrategy (#5)
1 parent 7722182 commit d6fa534

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Strategy/GithubStrategy.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function getCurrentRemoteVersion(Updater $updater)
101101
);
102102
}
103103

104-
$versions = array_keys($package['packages'][$this->getPackageName()]);
104+
$versions = array_column($package['packages'][$this->getPackageName()], 'version');
105105
$versionParser = new VersionParser($versions);
106106
if ($this->getStability() === self::STABLE) {
107107
$this->remoteVersion = $versionParser->getMostRecentStable();
@@ -115,7 +115,11 @@ public function getCurrentRemoteVersion(Updater $updater)
115115
* Setup remote URL if there's an actual version to download.
116116
*/
117117
if (! empty($this->remoteVersion)) {
118-
$this->remoteUrl = $this->getDownloadUrl($package);
118+
$chosenVersion = array_filter($package['packages'][$this->getPackageName()], function (array $package) {
119+
return $package['version'] === $this->remoteVersion;
120+
})[0];
121+
122+
$this->remoteUrl = $this->getDownloadUrl($chosenVersion);
119123
}
120124

121125
return $this->remoteVersion;
@@ -218,15 +222,14 @@ protected function getDownloadUrl(array $package)
218222
$baseUrl = preg_replace(
219223
'{\.git$}',
220224
'',
221-
$package['packages'][$this->getPackageName()][$this->remoteVersion]['source']['url']
225+
$package['source']['url']
222226
);
223-
$downloadUrl = sprintf(
227+
228+
return sprintf(
224229
'%s/releases/download/%s/%s',
225230
$baseUrl,
226231
$this->remoteVersion,
227232
$this->getPharName()
228233
);
229-
230-
return $downloadUrl;
231234
}
232235
}

tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ private function createTestPharAndKey(): void
139139
file_put_contents($this->tmp.'/packages.json', json_encode([
140140
'packages' => [
141141
'humbug/test-phar' => [
142-
'1.0.1' => [
142+
[
143+
'version' => '1.0.1',
143144
'source' => [
144145
'url' => 'file://'.$this->tmp.'.git',
145146
],
146147
],
147-
'1.0.0' => [
148+
[
149+
'version' => '1.0.0',
148150
],
149151
],
150152
],

0 commit comments

Comments
 (0)