Skip to content

Commit d847c66

Browse files
committed
Improve README.md
1 parent 5784346 commit d847c66

File tree

1 file changed

+70
-79
lines changed

1 file changed

+70
-79
lines changed

README.md

Lines changed: 70 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
<div align="center">
2+
<h1><img src=".github/packapi.png" alt="Pack API" width="100%" /></h1>
23

3-
<h1>Pack 📦 API</h1>
4-
5-
```bash
6-
composer req smnandre/packapi
7-
```
8-
9-
&nbsp; ![PHP Version](https://img.shields.io/badge/PHP-8.3+-2e7d32?logoColor=6AB76E&labelColor=010)
10-
&nbsp; ![CI](https://img.shields.io/github/actions/workflow/status/smnandre/packapi/CI.yaml?branch=main&label=Tests&logoColor=white&logoSize=auto&labelColor=010&color=388e3c)
11-
&nbsp; ![Release](https://img.shields.io/github/v/release/smnandre/packapi?label=Stable&logoColor=white&logoSize=auto&labelColor=010&color=43a047)
12-
&nbsp; [![GitHub Sponsors](https://img.shields.io/github/sponsors/smnandre?logo=github-sponsors&logoColor=66bb6a&logoSize=auto&label=%20Sponsor&labelColor=010&color=a5d6a7)](https://github.com/sponsors/smnandre)
13-
&nbsp; ![License](https://img.shields.io/github/license/smnandre/packapi?label=License&logoColor=white&logoSize=auto&labelColor=010&color=2e7d32)
4+
&nbsp; ![PHP Version](https://img.shields.io/badge/PHP-8.3+-7A8593?logoColor=7A8593&labelColor=161406)
5+
&nbsp; ![CI](https://img.shields.io/github/actions/workflow/status/smnandre/packapi/CI.yaml?branch=main&label=Tests&labelColor=161406&color=7A8593)
6+
&nbsp; ![Release](https://img.shields.io/github/v/release/smnandre/packapi?label=Stable&labelColor=161406&color=7A8593)
7+
&nbsp; [![GitHub Sponsors](https://img.shields.io/github/sponsors/smnandre?logo=githubsponsors&logoColor=7A8593&label=%20Sponsor&labelColor=161406&color=7A8593)](https://github.com/sponsors/smnandre)
8+
&nbsp; ![License](https://img.shields.io/github/license/smnandre/packapi?label=License&labelColor=161406&color=7A8593)
149

1510
</div>
1611

17-
18-
**PackAPI** is a small and extensible PHP library for analyzing Open Source packages across multiple ecosystems.
19-
20-
Get comprehensive insights about **Composer**, **NPM**, **GitHub repositories**, and more through a unified, strongly-typed API.
12+
Get insights from **Composer**, **NPM**, **GitHub**, and more via a unified, strongly‑typed API.
2113

2214

2315
## Features
2416

25-
- **Multi-Ecosystem Support**: Composer, NPM, GitHub, jsDelivr, OSV Security Database, BundlePhobia
26-
- **Rich Package Analytics**: Metadata, download stats, security advisories, project activity, quality scoring
27-
- **Security-First**: Built-in security advisory scanning and vulnerability detection
28-
- **Fully Tested**: 334+ tests with comprehensive coverage
29-
- **Type-Safe**: Strict typing throughout with PHP 8.3+ features
30-
- **Extensible**: Plugin architecture for adding new package sources
31-
- **Minimal Dependencies**: Built on Symfony components and PSR interfaces
32-
- **HTTP/3 (QUIC) Ready**: Modern networking with fallback to HTTP/2/1.1
17+
- **Multi‑ecosystem**: Composer, NPM, GitHub, jsDelivr, OSV, BundlePhobia
18+
- **Analyses**: Metadata, downloads, security, activity, quality
19+
- **Strong typing**: PHP 8.3+ with strict types
20+
- **Extensible**: Provider/factory architecture
21+
- **Well‑tested**: Extensive automated test suite
22+
- **Lean deps**: Symfony components and PSR interfaces
23+
- **HTTP/3 (QUIC)** support with graceful fallback
3324

3425
## Quick Start
3526

@@ -42,25 +33,31 @@ composer require smnandre/packapi
4233
### Basic Usage
4334

4435
```php
45-
use PackApi\Builder\PackApiBuilder;
36+
use PackApi\Bridge\Packagist\PackagistProviderFactory;
37+
use PackApi\Http\HttpClientFactory;
38+
use PackApi\Inspector\{MetadataInspector, DownloadStatsInspector};
4639
use PackApi\Package\ComposerPackage;
4740

48-
// Create the analyzer
49-
$packApi = (new PackApiBuilder())
50-
->withGitHubToken($_ENV['GITHUB_TOKEN'] ?? null) // Optional: for higher rate limits
51-
->build();
41+
$http = new HttpClientFactory();
42+
$packagist = new PackagistProviderFactory($http);
43+
44+
$metadata = new MetadataInspector([
45+
$packagist->createMetadataProvider(),
46+
]);
47+
$downloads = new DownloadStatsInspector([
48+
$packagist->createStatsProvider(),
49+
]);
5250

53-
// Analyze any package
5451
$package = new ComposerPackage('symfony/console');
55-
$analysis = $packApi->analyze($package);
52+
$meta = $metadata->getMetadata($package);
53+
$stats = $downloads->getStats($package);
5654

57-
// Get comprehensive data
58-
echo "Package: " . $analysis['metadata']->getName() . "\n";
59-
echo "Downloads: " . $analysis['downloads']->get('monthly')?->getCount() . "\n";
60-
echo "Quality Grade: " . $analysis['quality']->getGrade() . "\n";
61-
echo "Security Issues: " . count($analysis['security']) . "\n";
55+
echo 'Package: '.($meta?->name ?? 'N/A')."\n";
56+
echo 'Monthly downloads: '.($stats?->get('monthly')?->getCount() ?? 'N/A')."\n";
6257
```
6358

59+
For activity, content, quality, and OSV security, add the relevant provider factories (GitHub, jsDelivr, OSV) and pass them to the corresponding inspectors.
60+
6461
## Supported Package Types
6562

6663
| Ecosystem | Package Type | Metadata | Downloads | Security | Activity | Content | Bundle Size |
@@ -165,22 +162,17 @@ $inspector = new ContentInspector([
165162
$content = $inspector->getContentOverview($package);
166163

167164
echo "Files: " . $content->getFileCount() . "\n";
168-
echo "Total size: " . $content->getHumanSize() . "\n";
165+
echo "Total size: " . number_format($content->getTotalSize()) . " bytes\n";
169166
echo "Has README: " . ($content->hasReadme() ? 'Yes' : 'No') . "\n";
170167
echo "Has tests: " . ($content->hasTests() ? 'Yes' : 'No') . "\n";
171-
172-
// List largest files
173-
foreach ($content->getLargestFiles(5) as $file) {
174-
echo "FILE: {$file->getPath()}: {$file->getHumanSize()}\n";
175-
}
176168
```
177169

178170
### Bundle Size Analysis (NPM)
179171

180172
```php
181173
use PackApi\Bridge\BundlePhobia\BundlePhobiaProviderFactory;
182-
183-
$factory = new BundlePhobiaProviderFactory($httpClient);
174+
$httpFactory = new HttpClientFactory();
175+
$factory = new BundlePhobiaProviderFactory($httpFactory);
184176
$sizeProvider = $factory->createBundleSizeProvider();
185177

186178
$package = new NpmPackage('lodash');
@@ -195,9 +187,9 @@ if ($bundleSize) {
195187

196188
## Configuration
197189

198-
### HTTP/3 (QUIC) Support
190+
### HTTP/3 (QUIC)
199191

200-
PackAPI supports HTTP/3 for improved performance:
192+
PackApi supports HTTP/3 for improved performance:
201193

202194
```php
203195
use PackApi\Http\HttpClientFactory;
@@ -210,47 +202,27 @@ $client = $httpFactory->createClient([
210202

211203
### Caching
212204

213-
Add caching for better performance:
214-
215-
```php
216-
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
217-
218-
$cache = new FilesystemAdapter('packapi', 3600); // 1 hour TTL
219-
220-
$packApi = (new PackApiBuilder())
221-
->useCache($cache)
222-
->build();
223-
```
205+
Enable HTTP caching at the Symfony HTTP client level (e.g., `CachingHttpClient` with an HttpKernel `Store`). PackApi does not require a separate configuration object.
224206

225207
### Logging
226208

227-
Enable request logging for debugging:
228-
229-
```php
230-
use Psr\Log\LoggerInterface;
231-
232-
$packApi = (new PackApiBuilder())
233-
->withLogger($logger)
234-
->build();
235-
```
209+
Pass a PSR‑3 logger to `HttpClientFactory` to log outgoing requests in examples and providers.
236210

237211
### GitHub Authentication
238212

239-
For higher rate limits, provide a GitHub token:
213+
For higher GitHub rate limits, provide a token:
240214

241215
```php
242216
// Via environment variable
243217
$_ENV['GITHUB_TOKEN'] = 'ghp_your_token_here';
244218

245-
// Or directly
246-
$packApi = (new PackApiBuilder())
247-
->withGitHubToken('ghp_your_token_here')
248-
->build();
219+
// Pass the token to GitHubProviderFactory when creating providers
220+
// $github = new GitHubProviderFactory($httpFactory, $_ENV['GITHUB_TOKEN'] ?? null);
249221
```
250222

251223
## Architecture
252224

253-
PackAPI uses a clean, extensible architecture:
225+
PackApi uses a clean, extensible architecture:
254226

255227
### Core Components
256228

@@ -262,21 +234,21 @@ PackAPI uses a clean, extensible architecture:
262234

263235
### Provider Pattern
264236

237+
Each inspector accepts one or more providers from the corresponding factory. Providers are tried in order until one succeeds.
238+
265239
```php
266-
// Each inspector can have multiple providers
267-
$securityInspector = new SecurityInspector([
268-
new OSVSecurityProvider($httpClient), // OSV Database
269-
new GitHubSecurityProvider($httpClient), // GitHub Advisories
270-
new PackagistSecurityProvider($httpClient) // Packagist Security
240+
$security = new SecurityInspector([
241+
$osvFactory->createSecurityProvider(),
242+
$githubFactory->createSecurityProvider(),
243+
$packagistFactory->createSecurityProvider(),
271244
]);
272245

273-
// Providers are tried in order until one succeeds
274-
$advisories = $securityInspector->getSecurityAdvisories($package);
246+
$advisories = $security->getSecurityAdvisories($package);
275247
```
276248

277249
## Testing
278250

279-
PackAPI has comprehensive test coverage:
251+
PackApi has comprehensive test coverage:
280252

281253
```bash
282254
# Run tests
@@ -292,6 +264,25 @@ composer cs
292264
composer cs-fix
293265
```
294266

267+
## Examples
268+
269+
Run the sample scripts in `examples/` to try PackApi quickly:
270+
271+
- `examples/metadata-analysis.php`: print package metadata
272+
- `examples/download-stats-analysis.php`: print download periods
273+
- `examples/content-analysis.php`: analyze files and flags
274+
- `examples/activity-analysis.php`: summarize repo activity (set `GITHUB_TOKEN` for richer data)
275+
- `examples/security-analysis.php`: list security advisories (OSV/GitHub)
276+
- `examples/bundlephobia-size.php`: show NPM bundle sizes
277+
- `examples/all-analysis.php`: run a combined analysis with sensible fallbacks
278+
279+
Usage:
280+
281+
```bash
282+
php examples/metadata-analysis.php
283+
php examples/all-analysis.php
284+
```
285+
295286
### Adding New Providers
296287

297288
```php

0 commit comments

Comments
 (0)