From c676ce011eabad4a4eaa3748162772b92b10f7a2 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 1 Mar 2022 00:16:43 -0800 Subject: [PATCH] Fix bug where packages with a null description would cause a return type error Also adds .editorconfig configuration for IDE compatibility --- .editorconfig | 18 ++++++++++++++++++ .../Api/Fixture/get_null_description.json | 1 + spec/Packagist/Api/Result/FactorySpec.php | 9 ++++++++- src/Packagist/Api/Result/Factory.php | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 spec/Packagist/Api/Fixture/get_null_description.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a8b2271 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,json}] +indent_size = 2 + +[composer.json] +indent_size = 4 diff --git a/spec/Packagist/Api/Fixture/get_null_description.json b/spec/Packagist/Api/Fixture/get_null_description.json new file mode 100644 index 0000000..35d2446 --- /dev/null +++ b/spec/Packagist/Api/Fixture/get_null_description.json @@ -0,0 +1 @@ +{"package":{"name":"sylius\/sylius","description":null,"time":"2013-01-18T20:48:01+00:00","maintainers":[{"name":"pjedrzejewski","email":"pjedrzejewski@diweb.pl"}],"versions":{"dev-master":{"name":"sylius\/sylius","description":"Modern ecommerce for Symfony2","keywords":[],"homepage":"http:\/\/sylius.org","version":"dev-master","version_normalized":"9999999-dev","license":["MIT"],"authors":[{"name":"Pawe\u0142 J\u0119drzejewski","email":"pjedrzejewski@diweb.pl","homepage":"http:\/\/pjedrzejewski.com"},{"name":"Sylius project","homepage":"http:\/\/sylius.org"},{"name":"Community contributions","homepage":"http:\/\/github.com\/Sylius\/Sylius\/contributors"}],"source":{"type":"git","url":"https:\/\/github.com\/Sylius\/Sylius.git","reference":"1f0e49a6d4e9b6ab3a84cbd962f772c707461640"},"dist":{"type":"zip","url":"https:\/\/api.github.com\/repos\/Sylius\/Sylius\/zipball\/1f0e49a6d4e9b6ab3a84cbd962f772c707461640","reference":"1f0e49a6d4e9b6ab3a84cbd962f772c707461640","shasum":""},"type":"library","time":"2013-03-17T12:27:32+00:00","autoload":{"psr-0":{"Context":"features\/"}},"extra":{"symfony-app-dir":"sylius","symfony-web-dir":"web"},"require":{"php":">=5.3.3","doctrine\/orm":">=2.2.3,<2.4-dev","doctrine\/doctrine-fixtures-bundle":"*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","sylius\/core-bundle":"0.1.*","sylius\/web-bundle":"0.1.*","symfony\/symfony":">=2.2,<2.3-dev","doctrine\/doctrine-bundle":"1.2.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","mathiasverraes\/money":"dev-master@dev"},"require-dev":{"behat\/behat":"2.4.*","behat\/symfony2-extension":"*","behat\/mink-extension":"*","behat\/mink-browserkit-driver":"*","phpspec\/phpspec2":"dev-develop","behat\/mink-selenium2-driver":"*"}},"dev-checkout":{"name":"sylius\/sylius","description":"Modern ecommerce for Symfony2","keywords":[],"homepage":"","version":"dev-checkout","version_normalized":"dev-checkout","license":["MIT"],"authors":[{"name":"Pawe\u0142 J\u0119drzejewski","email":"pjedrzejewski@diweb.pl","homepage":"http:\/\/pjedrzejewski.com"},{"name":"Sylius project","homepage":"http:\/\/sylius.org"},{"name":"Community contributions","homepage":"http:\/\/github.com\/Sylius\/Sylius\/contributors"}],"source":{"type":"git","url":"https:\/\/github.com\/Sylius\/Sylius.git","reference":"cb0a489db41707d5df078f1f35e028e04ffd9e8e"},"dist":{"type":"zip","url":"https:\/\/api.github.com\/repos\/Sylius\/Sylius\/zipball\/cb0a489db41707d5df078f1f35e028e04ffd9e8e","reference":"cb0a489db41707d5df078f1f35e028e04ffd9e8e","shasum":""},"type":"library","time":"2013-03-01T22:22:37+00:00","autoload":{"psr-0":{"Context":"features\/"}},"extra":{"symfony-app-dir":"sylius","symfony-web-dir":"web"},"require":{"php":">=5.3.3","symfony\/symfony":">=2.2,<2.3-dev","doctrine\/orm":">=2.2.3,<2.4-dev","doctrine\/doctrine-bundle":"1.2.*","doctrine\/doctrine-fixtures-bundle":"*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","sylius\/core-bundle":"0.1.*","sylius\/web-bundle":"0.1.*","mathiasverraes\/money":"dev-master@dev"},"require-dev":{"behat\/behat":"2.4.*","behat\/symfony2-extension":"*","behat\/mink-extension":"*","behat\/mink-browserkit-driver":"*","phpspec\/phpspec2":"dev-develop","behat\/mink-selenium2-driver":"*"}}},"type":"library","repository":"https:\/\/github.com\/Sylius\/Sylius.git","downloads":{"total":41,"monthly":30,"daily":0},"favers":0}} diff --git a/spec/Packagist/Api/Result/FactorySpec.php b/spec/Packagist/Api/Result/FactorySpec.php index 500a543..9c9e329 100644 --- a/spec/Packagist/Api/Result/FactorySpec.php +++ b/spec/Packagist/Api/Result/FactorySpec.php @@ -82,10 +82,17 @@ function it_creates_packages_with_dependents() function it_creates_packages_with_null_source() { $data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_source.json'), true); - $this->create($data)->shouldHaveType('Packagist\Api\Result\Package'); } + function it_creates_packages_with_null_description() + { + $data = json_decode(file_get_contents('spec/Packagist/Api/Fixture/get_null_description.json'), true); + $result = $this->create($data); + $result->shouldHaveType('Packagist\Api\Result\Package'); + $result->getDescription()->shouldBe(''); + } + public function getMatchers(): array { return array( diff --git a/src/Packagist/Api/Result/Factory.php b/src/Packagist/Api/Result/Factory.php index b9eac7e..1f52ba0 100644 --- a/src/Packagist/Api/Result/Factory.php +++ b/src/Packagist/Api/Result/Factory.php @@ -81,6 +81,8 @@ public function createPackageResults(array $package) ); } + $package['description'] = (string) $package['description'] ?? ''; + foreach ($package['versions'] as $branch => $version) { if (isset($version['authors']) && $version['authors']) { foreach ($version['authors'] as $key => $author) {