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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Check coding standards
run: composer cs-check
run: vendor/bin/php-cs-fixer fix --dry-run --diff

stan:
name: PHPStan
Expand All @@ -61,10 +61,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "8.1", "8.2", "8.3", "8.4"]
php: ["8.2", "8.3", "8.4", "8.5"]
deps: ["highest"]
include:
- php: "8.0"
- php: "8.2"
deps: "lowest"
steps:
- uses: actions/checkout@v4
Expand Down
48 changes: 30 additions & 18 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@

declare(strict_types=1);

/*
* Shared php-cs-fixer configuration for every InitPHP package (ADR-005).
*
* This file is identical in all repositories as `.php-cs-fixer.dist.php`.
* The only package-specific part is the two lines below; scripts/check-cs-config.sh
* ignores exactly those two lines when it compares a package with this template.
* Keep each of them on a single line.
*/
$excludeDirs = [];
$excludePaths = ['Stubs/aws-sdk.php'];

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->notPath('Stubs/aws-sdk.php')
->name('*.php');

foreach ($excludeDirs as $excludeDir) {
$finder->exclude($excludeDir);
}

foreach ($excludePaths as $excludePath) {
$finder->notPath($excludePath);
}

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRiskyAllowed(false)
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'@PER-CS' => true,
'@PHP8x2Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'single_quote' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'],
],
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache');
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- **BREAKING:** Raised the minimum PHP version to 8.2 (was 8.0;
`"php": "^8.2"`). The CI matrix now covers PHP 8.2, 8.3, 8.4 and 8.5.
- **BREAKING:** The code style moved to PER-CS, enforced by the shared
PHP-CS-Fixer configuration (`.php-cs-fixer.dist.php`). The source was
reformatted accordingly; there are no behaviour changes.

## [2.0.0]

A correctness- and quality-focused overhaul: real bug fixes, consistent
`$target` semantics across adapters, a modern PHP 8 codebase, full tests,
static analysis, CI and documentation.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ a single, adapter-based API.

## Requirements

- PHP 8.0 or higher
- PHP 8.2 or higher
- `ext-fileinfo` (used to detect the real MIME type of a file)
- `ext-ftp` — only for the FTP adapter
- [`aws/aws-sdk-php`](https://packagist.org/packages/aws/aws-sdk-php) — only for the S3 adapter
Expand Down Expand Up @@ -129,7 +129,7 @@ Full guides with examples live in [`docs/`](docs/README.md):
## Contributing

Bug reports and pull requests are welcome. CI runs PHP-CS-Fixer, PHPStan (max
level) and PHPUnit across PHP 8.0–8.4; run the same bundle locally with:
level) and PHPUnit across PHP 8.2–8.5; run the same bundle locally with:

```bash
composer ci
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"docs": "https://github.com/InitPHP/Upload/tree/main/docs"
},
"require": {
"php": ">=8.0",
"php": "^8.2",
"ext-fileinfo": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.12 || ^2.1",
"friendsofphp/php-cs-fixer": "^3.65"
"friendsofphp/php-cs-fixer": "^3.95"
},
"suggest": {
"ext-ftp": "Required by the FTP adapter (InitPHP\\Upload\\Adapters\\FTPAdapter).",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parameters:
level: max
# Analyse against a fixed PHP version so results do not depend on the
# contributor's local runtime. 8.1+ is required for the `FTP\Connection`
# object the ftp_*() functions return; the library itself runs on 8.0+.
# object the ftp_*() functions return; the library itself runs on 8.2+.
phpVersion: 80200
paths:
- src
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/LocalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function ensureDirectory(string $directory): void
if ($directory === '' || is_dir($directory)) {
return;
}
if (!mkdir($directory, 0777, true) && !is_dir($directory)) {
if (!mkdir($directory, 0o777, true) && !is_dir($directory)) {
throw new UploadException(\sprintf('The target directory "%s" could not be created.', $directory));
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/UnsupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@
* extension (`ext-ftp`) or dependency (`aws/aws-sdk-php`) is missing. Extends
* {@see UploadException} so it is caught by the same handler.
*/
class UnsupportedException extends UploadException
{
}
class UnsupportedException extends UploadException {}
4 changes: 1 addition & 3 deletions src/Exceptions/UploadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@
* every runtime error raised by the package, so a single
* `catch (UploadException $e)` covers them all.
*/
class UploadException extends RuntimeException
{
}
class UploadException extends RuntimeException {}
4 changes: 1 addition & 3 deletions src/Exceptions/UploadInvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@
* than {@see UploadException}, signalling a misuse of the API rather than a
* runtime upload failure.
*/
class UploadInvalidArgumentException extends InvalidArgumentException
{
}
class UploadInvalidArgumentException extends InvalidArgumentException {}
4 changes: 2 additions & 2 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(
?string $name = null,
?int $size = null,
?string $type = null,
int $error = UPLOAD_ERR_OK
int $error = UPLOAD_ERR_OK,
) {
$this->path = $path;
$this->name = $name ?? basename($path);
Expand Down Expand Up @@ -165,7 +165,7 @@ private static function fromRow(array $row): ?self
self::asString($row['name'] ?? ''),
self::asInt($row['size'] ?? 0),
self::asString($row['type'] ?? ''),
$error
$error,
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CredentialsAndOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testConstructorMergesDefaultOptions(): void

self::assertSame(
['allowed_extensions' => [], 'allowed_mime_types' => [], 'allowed_max_size' => 0],
$adapter->exposeOptions()
$adapter->exposeOptions(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/LocalAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testRejectsADisallowedExtensionBeforeWriting(): void

$adapter = new LocalAdapter(
['dir' => $dir, 'url' => 'https://e.test'],
['allowed_extensions' => ['txt']]
['allowed_extensions' => ['txt']],
);

$this->expectException(UploadException::class);
Expand Down
4 changes: 1 addition & 3 deletions tests/Support/RecordingS3Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ final class RecordingS3Client extends S3Client
/** The `ObjectURL` to report; null simulates a missing URL in the result. */
public ?string $objectUrl = 'https://example-bucket.s3.amazonaws.com/source.txt';

public function __construct()
{
}
public function __construct() {}

/**
* @param array<string, mixed> $args
Expand Down
2 changes: 1 addition & 1 deletion tests/UploadTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function tearDown(): void
protected function makeDir(): string
{
$dir = sys_get_temp_dir() . '/upload-test-' . uniqid('', true);
if (!mkdir($dir, 0777, true) && !is_dir($dir)) {
if (!mkdir($dir, 0o777, true) && !is_dir($dir)) {
self::fail(\sprintf('Could not create temp directory "%s".', $dir));
}
$this->tempDirs[] = $dir;
Expand Down
Loading