Skip to content

Commit

Permalink
Update return types, make licenses an array, update phpspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Dec 1, 2020
1 parent 75091f0 commit 2086ee8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,5 +1,6 @@
/spec export-ignore
/examples export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
Expand Down
14 changes: 7 additions & 7 deletions spec/Packagist/Api/Result/Package/VersionSpec.php
Expand Up @@ -13,7 +13,7 @@

class VersionSpec extends ObjectBehavior
{
public function let(Author $author, Source $source, Dist $dist, \DateTime $time)
public function let(Author $author, Source $source, Dist $dist)
{
$this->fromArray([
'name' => 'sylius/sylius',
Expand All @@ -22,12 +22,12 @@ public function let(Author $author, Source $source, Dist $dist, \DateTime $time)
'homepage' => 'http://sylius.com',
'version' => 'dev-checkout',
'version_normalized' => 'dev-checkout',
'license' => 'MIT',
'licenses' => ['MIT'],
'authors' => [$author],
'source' => $source,
'dist' => $dist,
'type' => 'library',
'time' => $time,
'time' => '2020-01-25T15:11:19+00:00',
'autoload' => ['psr-0' => ['Context' => 'features/']],
'extra' => ['symfony-app-dir' => 'sylius'],
'require' => ['php' => '>=5.4'],
Expand Down Expand Up @@ -77,9 +77,9 @@ public function it_gets_normalized_version()
$this->getVersionNormalized()->shouldReturn('dev-checkout');
}

public function it_gets_license()
public function it_gets_licenses()
{
$this->getLicense()->shouldReturn('MIT');
$this->getLicenses()->shouldReturn(['MIT']);
}

public function it_has_authors($author)
Expand All @@ -102,9 +102,9 @@ public function it_gets_type()
$this->getType()->shouldReturn('library');
}

public function it_gets_time($time)
public function it_gets_time()
{
$this->getTime()->shouldReturn($time);
$this->getTime()->shouldReturn('2020-01-25T15:11:19+00:00');
}

public function it_gets_autoload()
Expand Down
10 changes: 4 additions & 6 deletions spec/Packagist/Api/Result/PackageSpec.php
Expand Up @@ -6,21 +6,19 @@

use Packagist\Api\Result\AbstractResult;
use Packagist\Api\Result\Package;
use Packagist\Api\Result\Package\Dist;
use Packagist\Api\Result\Package\Downloads;
use Packagist\Api\Result\Package\Maintainer;
use Packagist\Api\Result\Package\Source;
use Packagist\Api\Result\Package\Version;
use PhpSpec\ObjectBehavior;

class PackageSpec extends ObjectBehavior
{
public function let(Maintainer $maintainer, Version $version, Source $source, Dist $dist, Downloads $downloads, \DateTime $time)
public function let(Maintainer $maintainer, Version $version, Downloads $downloads)
{
$this->fromArray([
'name' => 'sylius/sylius',
'description' => 'Modern ecommerce for Symfony2',
'time' => $time,
'time' => '2020-01-25T15:11:19+00:00',
'maintainers' => [$maintainer],
'versions' => [$version],
'type' => 'library',
Expand Down Expand Up @@ -54,9 +52,9 @@ public function it_gets_description()
$this->getDescription()->shouldReturn('Modern ecommerce for Symfony2');
}

public function it_gets_time($time)
public function it_gets_time()
{
$this->getTime()->shouldReturn($time);
$this->getTime()->shouldReturn('2020-01-25T15:11:19+00:00');
}

public function it_gets_maintainers($maintainer)
Expand Down
6 changes: 3 additions & 3 deletions src/Packagist/Api/Client.php
Expand Up @@ -168,11 +168,11 @@ protected function respond(string $url)
* Execute the request URL
*
* @param string $url
* @return StreamInterface
* @return string
*/
protected function request(string $url): StreamInterface
protected function request(string $url): string
{
return $this->httpClient
return (string) $this->httpClient
->request('GET', $url)
->getBody();
}
Expand Down
15 changes: 15 additions & 0 deletions src/Packagist/Api/Result/Factory.php
Expand Up @@ -79,14 +79,29 @@ public function createPackageResults(array $package): Package
}

foreach ($package['versions'] as $branch => $version) {
if (empty($version['name']) && !empty($package['name'])) {
$version['name'] = $package['name'];
}

if (isset($version['license'])) {
$version['licenses'] = is_array($version['license']) ? $version['license'] : [$version['license']];
unset($version['license']);
}

// Cast some potentially null properties to empty strings
$version['name'] ??= '';
$version['type'] ??= '';

if (isset($version['authors']) && $version['authors']) {
foreach ($version['authors'] as $key => $author) {
$version['authors'][$key] = $this->createResult(Author::class, $author);
}
}

if ($version['source']) {
$version['source'] = $this->createResult(Source::class, $version['source']);
}

if (isset($version['dist']) && $version['dist']) {
$version['dist'] = $this->createResult(Dist::class, $version['dist']);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Packagist/Api/Result/Package.php
Expand Up @@ -8,23 +8,23 @@

class Package extends AbstractResult
{
protected string $name;
protected string $name = '';

protected string $description;
protected string $description = '';

protected string $time;
protected string $time = '';

protected array $maintainers;
protected array $maintainers = [];

protected array $versions;
protected array $versions = [];

protected string $type;
protected string $type = '';

protected string $repository;
protected string $repository = '';

protected Downloads $downloads;

protected string $favers;
protected int $favers = 0;

/**
* @var bool|string
Expand Down Expand Up @@ -85,7 +85,7 @@ public function getDownloads(): Downloads
return $this->downloads;
}

public function getFavers(): string
public function getFavers(): int
{
return $this->favers;
}
Expand Down
58 changes: 29 additions & 29 deletions src/Packagist/Api/Result/Package/Version.php
Expand Up @@ -8,47 +8,47 @@

class Version extends AbstractResult
{
protected string $name;
protected string $name = '';

protected string $description;
protected string $description = '';

protected array $keywords;
protected array $keywords = [];

protected string $homepage;
protected string $homepage = '';

protected string $version;
protected string $version = '';

protected string $versionNormalized;
protected string $versionNormalized = '';

protected string $license;
protected array $licenses = [];

protected array $authors;
protected array $authors = [];

protected Source $source;
protected ?Source $source;

protected Dist $dist;
protected ?Dist $dist;

protected string $type;
protected string $type = '';

protected string $time;
protected string $time = '';

protected array $autoload;
protected array $autoload = [];

protected array $extra;
protected array $extra = [];

protected array $require;
protected array $require = [];

protected array $requireDev;
protected array $requireDev = [];

protected string $conflict;
protected array $conflict = [];

protected string $provide;
protected array $provide = [];

protected string $replace;
protected array $replace = [];

protected string $bin;
protected array $bin = [];

protected array $suggest;
protected array $suggest = [];

/**
* @var bool|string
Expand Down Expand Up @@ -85,22 +85,22 @@ public function getVersionNormalized(): string
return $this->versionNormalized;
}

public function getLicense(): string
public function getLicenses(): array
{
return $this->license;
return $this->licenses;
}

public function getAuthors(): array
{
return $this->authors;
}

public function getSource(): Source
public function getSource(): ?Source
{
return $this->source;
}

public function getDist(): Dist
public function getDist(): ?Dist
{
return $this->dist;
}
Expand Down Expand Up @@ -135,22 +135,22 @@ public function getRequireDev(): array
return $this->requireDev;
}

public function getConflict(): string
public function getConflict(): array
{
return $this->conflict;
}

public function getProvide(): string
public function getProvide(): array
{
return $this->provide;
}

public function getReplace(): string
public function getReplace(): array
{
return $this->replace;
}

public function getBin(): string
public function getBin(): array
{
return $this->bin;
}
Expand Down

0 comments on commit 2086ee8

Please sign in to comment.