Skip to content

Commit 7378342

Browse files
Merge pull request #85 from robbieaverill/bugfix/nullable-downloads
Fix bug where null downlaods from Packagist API would result in an internal error
2 parents 6fbf8a3 + bbe7d62 commit 7378342

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"package":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","time":"2015-08-24T10:02:35+00:00","maintainers":[{"name":"Nyholm","avatar_url":"https:\/\/www.gravatar.com\/avatar\/ab19aada256f3dd9755a7b0152af7023?d=identicon"}],"versions":{"dev-master":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"dev-master","version_normalized":"dev-master","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"497c042a1b89434b0b874e32c80cec2f5a08cc17"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/497c042a1b89434b0b874e32c80cec2f5a08cc17","type":"zip","shasum":"","reference":"497c042a1b89434b0b874e32c80cec2f5a08cc17"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2017-12-17T15:45:48+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"default-branch":true,"require":{"php":"^5.5.9 || ^7.0","symfony\/framework-bundle":"^2.7 || ^3.0","sensio\/framework-extra-bundle":"^2.7 || ^3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"phpunit\/phpunit":"^4.5 || ^5.4","matthiasnoback\/symfony-dependency-injection-test":"^1.0","symfony\/symfony":"^2.3 || ^3.0","php-http\/guzzle6-adapter":"~1.0","php-http\/httplug-bundle":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.4.3":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.4.3","version_normalized":"0.4.3.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"acd3b8966764c121e8f2704545bddd716e94babf"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/acd3b8966764c121e8f2704545bddd716e94babf","type":"zip","shasum":"","reference":"acd3b8966764c121e8f2704545bddd716e94babf"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2017-06-08T14:46:55+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"^5.5.9 || ^7.0","symfony\/framework-bundle":"^2.7 || ^3.0","sensio\/framework-extra-bundle":"^2.7 || ^3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"phpunit\/phpunit":"^4.5 || ^5.4","matthiasnoback\/symfony-dependency-injection-test":"^1.0","symfony\/symfony":"^2.3 || ^3.0","php-http\/guzzle6-adapter":"~1.0","php-http\/httplug-bundle":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.4.2":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.4.2","version_normalized":"0.4.2.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"e4145af8e29a33a09bbe4874bee94dd6135fb1f6"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/e4145af8e29a33a09bbe4874bee94dd6135fb1f6","type":"zip","shasum":"","reference":"e4145af8e29a33a09bbe4874bee94dd6135fb1f6"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2016-04-23T08:23:26+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"php-http\/guzzle6-adapter":"~1.0","php-http\/httplug-bundle":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.4.1":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.4.1","version_normalized":"0.4.1.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"18440e14c20130076730589030966d40a78f6618"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/18440e14c20130076730589030966d40a78f6618","type":"zip","shasum":"","reference":"18440e14c20130076730589030966d40a78f6618"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2016-04-18T07:53:32+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"php-http\/guzzle6-adapter":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.4.0":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.4.0","version_normalized":"0.4.0.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"f787049394efe6e1755ba3c69d57fcb5c1364eb3"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/f787049394efe6e1755ba3c69d57fcb5c1364eb3","type":"zip","shasum":"","reference":"f787049394efe6e1755ba3c69d57fcb5c1364eb3"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2016-04-17T19:49:26+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"php-http\/guzzle6-adapter":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.3.0":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.3.0","version_normalized":"0.3.0.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"a13d16e185554fab1afcd90237a4bc57b9bc7d12"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/a13d16e185554fab1afcd90237a4bc57b9bc7d12","type":"zip","shasum":"","reference":"a13d16e185554fab1afcd90237a4bc57b9bc7d12"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2016-02-25T08:44:34+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"^1.0","php-http\/plugins":"^1.0","php-http\/client-implementation":"^1.0","psr\/log":"^1.0"},"require-dev":{"php-http\/guzzle6-adapter":"~1.0"},"suggest":{"php-http\/httplug-bundle":"To easier configure your httplug clients.","happyr\/auto-fallback-translation-bundle":"To automatically translate phrases that are missing form your secondary language."},"abandoned":"php-translation\/symfony-bundle"},"0.2.2":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.2.2","version_normalized":"0.2.2.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"fbae4cfe3c31ed0c45eca2aaef2be10ababdaee0"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/fbae4cfe3c31ed0c45eca2aaef2be10ababdaee0","type":"zip","shasum":"","reference":"fbae4cfe3c31ed0c45eca2aaef2be10ababdaee0"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2016-01-04T11:11:56+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"1.0.0-beta","php-http\/discovery":"^0.4|^0.5","php-http\/plugins":"dev-master","php-http\/client-implementation":"1.0","psr\/log":"1.0.0"},"require-dev":{"php-http\/guzzle5-adapter":"dev-master"},"abandoned":"php-translation\/symfony-bundle"},"0.2.1":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.2.1","version_normalized":"0.2.1.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"9ffd5b2d2966b3bd4aa8e3e2a2296b17e464470e"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/9ffd5b2d2966b3bd4aa8e3e2a2296b17e464470e","type":"zip","shasum":"","reference":"9ffd5b2d2966b3bd4aa8e3e2a2296b17e464470e"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2015-12-23T18:39:02+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"1.0.0-beta","php-http\/discovery":"^0.4","php-http\/plugins":"dev-master","php-http\/client-implementation":"1.0","psr\/log":"1.0.0"},"require-dev":{"php-http\/guzzle5-adapter":"dev-master"},"abandoned":"php-translation\/symfony-bundle"},"0.2.0":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.2.0","version_normalized":"0.2.0.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"f55e3862ea30fd24f4737d8046be7b6a7a6cd9ab"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/f55e3862ea30fd24f4737d8046be7b6a7a6cd9ab","type":"zip","shasum":"","reference":"f55e3862ea30fd24f4737d8046be7b6a7a6cd9ab"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2015-12-23T18:20:01+00:00","autoload":{"psr-4":{"Happyr\\TranslationBundle\\":"src\/"}},"require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","php-http\/httplug":"1.0.0-beta","php-http\/discovery":"^0.4","php-http\/plugins":"dev-master","php-http\/client-implementation":"1.0","psr\/log":"1.0.0"},"require-dev":{"php-http\/guzzle5-adapter":"dev-master"},"abandoned":"php-translation\/symfony-bundle"},"0.1.0":{"name":"happyr\/translation-bundle","description":"Integrate Symfony with translations SaaS like http:\/\/localise.biz","keywords":[],"homepage":"http:\/\/developer.happyr.com","version":"0.1.0","version_normalized":"0.1.0.0","license":["MIT"],"authors":[{"name":"Tobias Nyholm","email":"[email protected]"}],"source":{"url":"https:\/\/github.com\/Happyr\/TranslationBundle.git","type":"git","reference":"94b1202aaa7aeac253c9bf9ef5a7038b5768b296"},"dist":{"url":"https:\/\/api.github.com\/repos\/Happyr\/TranslationBundle\/zipball\/94b1202aaa7aeac253c9bf9ef5a7038b5768b296","type":"zip","shasum":"","reference":"94b1202aaa7aeac253c9bf9ef5a7038b5768b296"},"type":"symfony-bundle","support":{"issues":"https:\/\/github.com\/Happyr\/TranslationBundle\/issues","source":"https:\/\/github.com\/Happyr\/TranslationBundle\/tree\/master"},"time":"2015-12-23T16:20:42+00:00","autoload":{"psr-0":{"Happyr\\TranslationBundle\\":""}},"target-dir":"Happyr\/TranslationBundle","require":{"php":"\u003E=5.5.9","symfony\/symfony":"~2.7|~3.0","sensio\/framework-extra-bundle":"~2.7|~3.0","guzzlehttp\/guzzle":"~5.3|~6.0"},"abandoned":"php-translation\/symfony-bundle"}},"type":"symfony-bundle","repository":"https:\/\/github.com\/Happyr\/TranslationBundle","github_stars":52,"github_watchers":9,"github_forks":24,"github_open_issues":9,"language":"PHP","abandoned":"php-translation\/symfony-bundle","dependents":1,"suggesters":0,"downloads":null,"favers":null}}

spec/Packagist/Api/Result/FactorySpec.php

+20-13
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
class FactorySpec extends ObjectBehavior
1313
{
14-
public function it_is_initializable()
14+
public function it_is_initializable(): void
1515
{
1616
$this->shouldHaveType(Factory::class);
1717
}
1818

19-
public function it_creates_search_results()
19+
public function it_creates_search_results(): void
2020
{
2121
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/search.json'), true);
2222

@@ -28,7 +28,7 @@ public function it_creates_search_results()
2828
}
2929
}
3030

31-
public function it_creates_popular_results()
31+
public function it_creates_popular_results(): void
3232
{
3333
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/popular.json'), true);
3434

@@ -71,15 +71,15 @@ public function it_creates_composer_releases_packages(): void
7171
$results->shouldHaveCount(1);
7272
$results->shouldBeArray();
7373
foreach ($results as $result) {
74-
$result->shouldBeAnInstanceOf('Packagist\Api\Result\Package');
74+
$result->shouldBeAnInstanceOf(Package::class);
7575

7676
foreach ($result->getVersions() as $version) {
77-
$version->shouldBeAnInstanceOf('Packagist\Api\Result\Version');
77+
$version->shouldBeAnInstanceOf(Package\Version::class);
7878
}
7979
}
8080
}
8181

82-
public function it_creates_package_names()
82+
public function it_creates_package_names(): void
8383
{
8484
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/all.json'), true);
8585

@@ -90,46 +90,54 @@ public function it_creates_package_names()
9090
]);
9191
}
9292

93-
public function it_creates_packages_with_missing_optional_data()
93+
public function it_creates_packages_with_missing_optional_data(): void
9494
{
9595
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_nodist.json'), true);
9696

9797
$this->create($data)->shouldHaveType(Package::class);
9898
}
9999

100-
public function it_creates_abandoned_packages()
100+
public function it_creates_abandoned_packages(): void
101101
{
102102
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_abandoned.json'), true);
103103

104104
$this->create($data)->shouldHaveType(Package::class);
105105
}
106106

107-
public function it_creates_packages_with_suggesters()
107+
public function it_creates_packages_with_suggesters(): void
108108
{
109109
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_suggesters.json'), true);
110110
$this->create($data)->shouldHaveType(Package::class);
111111
}
112112

113-
public function it_creates_packages_with_dependents()
113+
public function it_creates_packages_with_dependents(): void
114114
{
115115
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_dependents.json'), true);
116116
$this->create($data)->shouldHaveType(Package::class);
117117
}
118118

119-
public function it_creates_packages_with_null_source()
119+
public function it_creates_packages_with_null_source(): void
120120
{
121121
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_source.json'), true);
122122
$this->create($data)->shouldHaveType(Package::class);
123123
}
124124

125-
public function it_creates_packages_with_null_description()
125+
public function it_creates_packages_with_null_description(): void
126126
{
127127
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_description.json'), true);
128128
$result = $this->create($data);
129129
$result->shouldHaveType(Package::class);
130130
$result->getDescription()->shouldBe('');
131131
}
132132

133+
public function it_creates_packages_with_null_downloads(): void
134+
{
135+
$data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_downloads.json'), true);
136+
$result = $this->create($data);
137+
$result->shouldHaveType(Package::class);
138+
$result->getDownloads()->shouldBeNull();
139+
}
140+
133141
public function getMatchers(): array
134142
{
135143
return array(
@@ -138,5 +146,4 @@ public function getMatchers(): array
138146
}
139147
);
140148
}
141-
142149
}

src/Packagist/Api/Result/Factory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function createPackageResults(array $package): Package
107107
$package['github_forks'] ??= 0;
108108
$package['suggesters'] ??= 0;
109109
$package['dependents'] ??= 0;
110+
$package['downloads'] ??= null;
110111
$package['favers'] ??= 0;
111112

112113
if (isset($package['maintainers']) && $package['maintainers']) {
@@ -115,7 +116,7 @@ public function createPackageResults(array $package): Package
115116
}
116117
}
117118

118-
if (isset($package['downloads']) && $package['downloads']) {
119+
if (isset($package['downloads']) && is_array($package['downloads'])) {
119120
$package['downloads'] = $this->createResult(Downloads::class, $package['downloads']);
120121
}
121122

src/Packagist/Api/Result/Package.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Package extends AbstractResult
2222

2323
protected string $repository = '';
2424

25-
protected Downloads $downloads;
25+
protected ?Downloads $downloads;
2626

2727
protected int $favers = 0;
2828

@@ -80,7 +80,7 @@ public function getRepository(): string
8080
return $this->repository;
8181
}
8282

83-
public function getDownloads(): Downloads
83+
public function getDownloads(): ?Downloads
8484
{
8585
return $this->downloads;
8686
}

0 commit comments

Comments
 (0)