Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.php.cs export-ignore
/.github export-ignore
/rector.php export-ignore
29 changes: 0 additions & 29 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'

permissions:
contents: write

jobs:
php-code-styling:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
14 changes: 9 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3, 8.4]
dependency-version: [prefer-stable]
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.0, 7.4, 7.3]
dependency-version: [prefer-lowest, prefer-stable]

include:
- php: 8.2
dependency-version: prefer-lowest
os: ubuntu-latest

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: main

Expand All @@ -21,7 +21,7 @@ jobs:
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
Expand Down
37 changes: 0 additions & 37 deletions .php-cs-fixer.dist.php

This file was deleted.

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ $packagist->getPackagesNamesByType('composer-plugin');
$packagist->getPackagesNamesByVendor('spatie');
```

### List popular packages
```php
// List first page of popular packages
$packagist->getPopularPackages();
```

#### Pagination
Listing popular packages returns a paginated result. You can change the pagination settings by adding more parameters.

```php
// Get the third page, 10 items per page.
$packagist->getPopularPackages(3, 10);
```

### Searching for packages
```php
// Search packages by name.
Expand Down Expand Up @@ -79,11 +93,20 @@ $packagist->searchPackagesByName('packagist', 3, 10);
$packagist->getPackageMetadata('spatie/packagist-api');
$packagist->getPackageMetadata('spatie', 'packagist-api');

// Using the Composer metadata for dev branches.
$packagist->getPackageMetadata('spatie', 'packagist-api', true);

// Using the API. (slower, cached for 12 hours by Packagist.
$packagist->getPackage('spatie/packagist-api');
$packagist->getPackage('spatie', 'packagist-api');
```

### Get package download stats
```php
$packagist->getPackageDownloadStats('spatie/packagist-api');
$packagist->getPackageDownloadStats('spatie', 'packagist-api');
```

### Get Statistics
```php
$packagist->getStatistics();
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^8.2",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.0",
"composer/semver": "^1.0|^2.0|^3.0"
"composer/semver": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.4",
"spatie/phpunit-snapshot-assertions": "^4.2"
"laravel/pint": "^1.17.3",
"phpunit/phpunit": "^11.5 || ^12.0",
"spatie/phpunit-snapshot-assertions": "^5.1"
},
"autoload": {
"psr-4": {
Expand All @@ -49,6 +50,6 @@
},
"scripts": {
"test": "vendor/bin/phpunit",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
"lint": "pint"
}
}
60 changes: 26 additions & 34 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Spatie Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Spatie Integration Test Suite">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="default">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
13 changes: 13 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withPreparedSets(codeQuality: true, phpunitCodeQuality: true)
->withPhpSets();
4 changes: 1 addition & 3 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use InvalidArgumentException as BaseInvalidArgumentException;

class InvalidArgumentException extends BaseInvalidArgumentException
{
}
class InvalidArgumentException extends BaseInvalidArgumentException {}
42 changes: 24 additions & 18 deletions src/PackagistClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@

class PackagistClient
{
/** @var \GuzzleHttp\Client */
protected $client;

/** @var \Spatie\Packagist\PackagistUrlGenerator */
protected $url;

public function __construct(Client $client, PackagistUrlGenerator $url)
{
$this->client = $client;

$this->url = $url;
}
public function __construct(
protected Client $client,
protected PackagistUrlGenerator $url
) {}

public function getPackagesNames(?string $type = null, ?string $vendor = null): ?array
{
return $this->request('packages/list.json', array_filter(compact('type', 'vendor')));
return $this->request('packages/list.json', array_filter(['type' => $type, 'vendor' => $vendor]));
}

public function getPackagesNamesByType(string $type): ?array
Expand All @@ -36,6 +28,14 @@ public function getPackagesNamesByVendor(string $vendor): ?array
return $this->getPackagesNames(null, $vendor);
}

public function getPopularPackages(?int $page = 1, int $perPage = 100): ?array
{
$filters['page'] = $page;
$filters['per_page'] = $perPage;

return $this->request('explore/popular.json', $filters);
}

public function searchPackages($name = null, array $filters = [], ?int $page = 1, int $perPage = 15): ?array
{
if (count(array_diff(array_keys($filters), ['tags', 'type'])) > 0) {
Expand Down Expand Up @@ -72,14 +72,22 @@ public function getPackage(string $vendor, ?string $package = null): ?array
return $this->request($resource, [], PackagistUrlGenerator::API_MODE);
}

public function getPackageMetadata(string $vendor, ?string $package = null): ?array
public function getPackageMetadata(string $vendor, ?string $package = null, bool $devVersions = false): ?array
{
[$vendor, $package] = PackagistVendorFormatter::format($vendor, $package);
$resource = 'p/'.$vendor.'/'.$package.'.json';
$resource = 'p2/'.$vendor.'/'.$package.($devVersions ? '~dev' : '').'.json';

return $this->request($resource, [], PackagistUrlGenerator::REPO_MODE);
}

public function getPackageDownloadStats(string $vendor, ?string $package = null): ?array
{
[$vendor, $package] = PackagistVendorFormatter::format($vendor, $package);
$resource = 'packages/'.$vendor.'/'.$package.'/stats.json';

return $this->request($resource, [], PackagistUrlGenerator::API_MODE);
}

public function getStatistics(): ?array
{
return $this->request('statistics.json');
Expand Down Expand Up @@ -120,9 +128,7 @@ public function getAdvisories(array $packages = [], ?int $updatedSince = null):
return [];
}

$advisories = $response['advisories'];

return $advisories;
return $response['advisories'];
}

public function getAdvisoriesAffectingVersions(array $packages = [], ?int $updatedSince = null): array
Expand Down
4 changes: 2 additions & 2 deletions src/PackagistUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
class PackagistUrlGenerator
{
public const API_MODE = 'base_url';

public const REPO_MODE = 'repo_url';

/** @var array */
private $config;
private array $config;

public function __construct(?string $baseUrl = null, ?string $repoUrl = null)
{
Expand Down
Loading