diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index 32b7340..af6d319 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -6,39 +6,27 @@ on: pull_request: branches: [main] +# The PHP version comes from the job container image instead of shivammathur/setup-php: +# the runner in this Gitea instance reaches github.com intermittently and setup-php +# failed with "TLS handshake timeout". Fewer external actions, fewer failure modes. jobs: check: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php: ['8.3', '8.4'] - - name: PHP ${{ matrix.php }} - - # The PHP version comes from the job container image instead of shivammathur/setup-php: - # the runner in this Gitea instance reaches github.com intermittently and setup-php - # failed with "TLS handshake timeout". Fewer external actions, fewer failure modes. - container: php:${{ matrix.php }}-cli - + name: PHP 8.4 + container: php:8.4-cli steps: - name: Install system packages run: | apt-get update -qq apt-get install -y -qq --no-install-recommends git unzip libxml2-dev > /dev/null - - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Install Composer run: | curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet - composer --version - - name: Install dependencies run: composer update --prefer-dist --no-interaction --no-progress - - name: Run gate run: composer check diff --git a/AGENTS.md b/AGENTS.md index 6ebcb17..c1d5b2f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -37,8 +37,8 @@ salvo lo que difiere abajo. Léelos antes de tocar el toolchain. | | aquí | en `../orm` | |---|---|---| -| PHP declarado | `>=8.3` | `>=8.3` (su prosa dice 8.2: gana el composer.json) | -| Parser Mago / PHPStan | 8.2 / `80300` | 8.2 / `80200` | +| PHP declarado | `>=8.4` | `>=8.4` | +| Parser Mago / PHPStan | 8.4 / `80400` | 8.4 / `80400` | | `mago-baseline.toml` | **no existe**, y no debe crearse | existe | ## Independencia del ORM (decisión de diseño, no descuido) @@ -65,8 +65,8 @@ la app conecta el ORM por composición. Consecuencias que un agente rompería po ## Entorno local -- PHP: `C:\php8.4\php.exe` (8.4.19), Composer 2.10.3. La librería declara `>=8.3`, así que **no** - uses sintaxis exclusiva de 8.4; por eso `(new Foo())->bar()` conserva los paréntesis. +- PHP: `C:\php8.4\php.exe` (8.4.19), Composer 2.10.3. La librería declara `>=8.4`, así que toda la + sintaxis de 8.4 está disponible. - `declare(strict_types=1)` en todo archivo, incluidos los tests. - Sin `.env` ni servicios externos. Los tests son unitarios y puros: no levantan servidor, ni base, ni red. Un test que necesite un socket real está mal ubicado aquí. @@ -87,9 +87,10 @@ vendor/bin/phpunit --configuration phpunit.xml.dist --filter NombreDelTest ## Trampas del toolchain -- **`php-version = "8.2"` en `mago.toml` es obligatorio.** Subirlo a 8.4 hace que `mago fmt` - reescriba `(new X())->m()` como `new X()->m()`, que rompe el soporte declarado y ni siquiera parsea - cuando el resultado se asigna. +- **`php-version = "8.4"` en `mago.toml` debe coincidir con el mínimo declarado.** El paquete + promete `>=8.4`, así que `mago fmt` puede emitir `new X()->m()`. Si el soporte mínimo bajara, + `php-version` tendría que bajar con él: con 8.4 el formatter elimina los paréntesis de + `(new X())->m()`, sintaxis que no parsea en 8.3 ni inferiores. - `mago analyze` excluye `tests/` (no carga el autoloader de Composer): reportaría `TestCase` como clase inexistente. PHPStan sí cubre los tests. - **Sin baseline.** El baseline del ORM acepta `mixed` inherente a PDO. Aquí no hay PDO como diff --git a/README.md b/README.md index 5974af9..3979515 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Framework-agnostic REST controller toolkit: routing, request parsing, validation over any data source. Vanilla PHP, no framework. - **Package:** `camelia/controllers` — **Namespace:** `Camelia\Controllers` -- **PHP** `>=8.3`, extension `json` +- **PHP** `>=8.4`, extension `json` ## What it is diff --git a/composer.json b/composer.json index 12cde84..ae39ae5 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ } ], "require": { - "php": ">=8.3", + "php": ">=8.4", "ext-json": "*" }, "require-dev": { "carthage-software/mago": "^1.60", - "phpstan/phpstan": "^1.11", + "phpstan/phpstan": "2.3", "phpunit/phpunit": "^10.5 || ^11.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index 7eecf79..23ededd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c828e25914c9dd9e5cf7667b446f40ad", + "content-hash": "15c8e8773869cdb0c6dab80f2e5211b7", "packages": [], "packages-dev": [ { @@ -308,15 +308,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.34", + "version": "2.3.0", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4dd89ca7aa30fdc6760be21550d583bcc32e8476", - "reference": "4dd89ca7aa30fdc6760be21550d583bcc32e8476", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b1f9890d9af53a25c58129e78f0aadd31f90d7f4", + "reference": "b1f9890d9af53a25c58129e78f0aadd31f90d7f4", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -335,6 +335,17 @@ "license": [ "MIT" ], + "authors": [ + { + "name": "Ondřej Mirtes" + }, + { + "name": "Markus Staab" + }, + { + "name": "Vincent Langlet" + } + ], "description": "PHPStan - PHP Static Analysis Tool", "keywords": [ "dev", @@ -357,7 +368,7 @@ "type": "github" } ], - "time": "2026-07-28T10:04:39+00:00" + "time": "2026-10-06T06:15:36+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1967,7 +1978,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.3", + "php": ">=8.4", "ext-json": "*" }, "platform-dev": {}, diff --git a/mago.toml b/mago.toml index 52f3b21..281acdb 100644 --- a/mago.toml +++ b/mago.toml @@ -1,9 +1,8 @@ # Mago toolchain configuration — camelia/controllers # Docs: https://mago.carthage.software -# The library promises PHP >= 8.3. Pinning the parser to 8.2 keeps the formatter from emitting -# syntax the package cannot ship (for example `new Foo()->bar()`, which needs 8.4). -php-version = "8.2" +# The library promises PHP >= 8.4. +php-version = "8.4" [source] paths = ["src", "tests"] diff --git a/phpstan.neon b/phpstan.neon index a0a7c20..84126b1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,7 @@ parameters: level: 8 - # The library promises PHP >= 8.3, so analysis targets the oldest supported version. - # This is why `(new Foo())->bar()` keeps its parentheses: `new Foo()->bar()` only parses on 8.4+. - phpVersion: 80300 + # The library promises PHP >= 8.4, so analysis targets the only supported version. + phpVersion: 80400 paths: - src - tests diff --git a/tests/Fixture/ArrayGateway.php b/tests/Fixture/ArrayGateway.php index 43237b3..cd3616a 100644 --- a/tests/Fixture/ArrayGateway.php +++ b/tests/Fixture/ArrayGateway.php @@ -61,7 +61,7 @@ final class ArrayGateway implements ResourceGateway return true; } - public function count(array $query = []): ?int + public function count(array $query = []): int { return count($this->records); } diff --git a/tests/Unit/CrudControllerTest.php b/tests/Unit/CrudControllerTest.php index ba01236..4fc5018 100644 --- a/tests/Unit/CrudControllerTest.php +++ b/tests/Unit/CrudControllerTest.php @@ -158,7 +158,7 @@ final class CrudControllerTest extends TestCase private function withId(string $method, string $id): Request { - return (new JsonRequest(method: $method, path: '/articulos/' . $id))->withAttribute( + return new JsonRequest(method: $method, path: '/articulos/' . $id)->withAttribute( 'id', $id, ); diff --git a/tests/Unit/JsonRequestTest.php b/tests/Unit/JsonRequestTest.php index f6280d1..51b899e 100644 --- a/tests/Unit/JsonRequestTest.php +++ b/tests/Unit/JsonRequestTest.php @@ -52,7 +52,7 @@ final class JsonRequestTest extends TestCase public function testWithAttributeKeepsPreviousAttributes(): void { - $request = (new JsonRequest()) + $request = new JsonRequest() ->withAttribute('a', '1') ->withAttribute('b', '2'); diff --git a/tests/Unit/Middleware/ContentNegotiationTest.php b/tests/Unit/Middleware/ContentNegotiationTest.php index 7b2a24d..7cfd6fe 100644 --- a/tests/Unit/Middleware/ContentNegotiationTest.php +++ b/tests/Unit/Middleware/ContentNegotiationTest.php @@ -19,7 +19,7 @@ final class ContentNegotiationTest extends TestCase public function testAddsContentType(): void { - $response = (new ContentNegotiation())->process(new JsonRequest(), self::ok(...)); + $response = new ContentNegotiation()->process(new JsonRequest(), self::ok(...)); self::assertSame(200, $response->status()); self::assertSame('application/json; charset=utf-8', $response->headers()['Content-Type']); @@ -27,14 +27,14 @@ final class ContentNegotiationTest extends TestCase public function testMissingAcceptHeaderIsAccepted(): void { - $response = (new ContentNegotiation())->process(new JsonRequest(), self::ok(...)); + $response = new ContentNegotiation()->process(new JsonRequest(), self::ok(...)); self::assertSame(200, $response->status()); } public function testJsonAcceptIsAccepted(): void { - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(headers: ['accept' => 'application/json']), self::ok(...), ); @@ -46,7 +46,7 @@ final class ContentNegotiationTest extends TestCase { $accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(headers: ['accept' => $accept]), self::ok(...), ); @@ -56,7 +56,7 @@ final class ContentNegotiationTest extends TestCase public function testIncompatibleAcceptIs406(): void { - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(headers: ['accept' => 'application/xml']), static function (): Response { self::fail('The handler must not run when the client rejects JSON.'); @@ -69,7 +69,7 @@ final class ContentNegotiationTest extends TestCase public function testZeroQualityIsRejected(): void { - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(headers: ['accept' => 'application/json;q=0']), static function (): Response { self::fail('A q=0 entry means not acceptable.'); @@ -81,7 +81,7 @@ final class ContentNegotiationTest extends TestCase public function testNonZeroQualityIsAccepted(): void { - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(headers: ['accept' => 'application/json;q=0.5']), self::ok(...), ); @@ -91,7 +91,7 @@ final class ContentNegotiationTest extends TestCase public function testExistingContentTypeIsPreserved(): void { - $response = (new ContentNegotiation())->process( + $response = new ContentNegotiation()->process( new JsonRequest(), static fn(): Response => new Response(['ok' => true], 200, [ 'Content-Type' => 'application/problem+json', @@ -103,7 +103,7 @@ final class ContentNegotiationTest extends TestCase public function testContentTypeCanBeDisabled(): void { - $response = (new ContentNegotiation(addContentType: false))->process( + $response = new ContentNegotiation(addContentType: false)->process( new JsonRequest(), self::ok(...), ); diff --git a/tests/Unit/Security/BearerAuthTest.php b/tests/Unit/Security/BearerAuthTest.php index e96a9fc..ee0b975 100644 --- a/tests/Unit/Security/BearerAuthTest.php +++ b/tests/Unit/Security/BearerAuthTest.php @@ -88,7 +88,7 @@ final class BearerAuthTest extends TestCase public function testRouterRejectsBeforeReachingController(): void { - $router = (new Router())->withMiddleware( + $router = new Router()->withMiddleware( new BearerAuth(static fn(string $token): ?array => null), ); $router->get('/x', static fn(): Response => new Response(['leaked' => true])); @@ -101,7 +101,7 @@ final class BearerAuthTest extends TestCase public function testRouterAllowsValidToken(): void { - $router = (new Router())->withMiddleware(new BearerAuth(static fn(string $token): array => [ + $router = new Router()->withMiddleware(new BearerAuth(static fn(string $token): array => [ 'id' => 1, ])); $router->get( diff --git a/tests/Unit/Security/CorsTest.php b/tests/Unit/Security/CorsTest.php index c4f6029..3cb295d 100644 --- a/tests/Unit/Security/CorsTest.php +++ b/tests/Unit/Security/CorsTest.php @@ -38,7 +38,7 @@ final class CorsTest extends TestCase public function testWildcardOriginIsAddedToResponse(): void { - $response = (new Cors())->process( + $response = new Cors()->process( new JsonRequest(headers: ['origin' => 'https://app.test']), self::passThrough(...), ); diff --git a/tests/Unit/Security/RateLimitTest.php b/tests/Unit/Security/RateLimitTest.php index f038d9b..850a0e1 100644 --- a/tests/Unit/Security/RateLimitTest.php +++ b/tests/Unit/Security/RateLimitTest.php @@ -89,8 +89,8 @@ final class RateLimitTest extends TestCase public function testBucketsAreSeparatedByClientAddress(): void { $limiter = $this->limiter(1); - $first = (new JsonRequest())->withAttribute('client_ip', '10.0.0.1'); - $second = (new JsonRequest())->withAttribute('client_ip', '10.0.0.2'); + $first = new JsonRequest()->withAttribute('client_ip', '10.0.0.1'); + $second = new JsonRequest()->withAttribute('client_ip', '10.0.0.2'); self::assertSame(200, $limiter->process($first, self::passThrough(...))->status()); self::assertSame(200, $limiter->process($second, self::passThrough(...))->status()); diff --git a/tests/Unit/Security/RequireRoleTest.php b/tests/Unit/Security/RequireRoleTest.php index ef0aac5..0da8be9 100644 --- a/tests/Unit/Security/RequireRoleTest.php +++ b/tests/Unit/Security/RequireRoleTest.php @@ -19,15 +19,12 @@ final class RequireRoleTest extends TestCase private static function withUser(mixed $user): Request { - return (new JsonRequest())->withAttribute('user', $user); + return new JsonRequest()->withAttribute('user', $user); } public function testNoIdentityIs401(): void { - $response = (new RequireRole(['admin']))->process( - new JsonRequest(), - self::passThrough(...), - ); + $response = new RequireRole(['admin'])->process(new JsonRequest(), self::passThrough(...)); self::assertSame(401, $response->status()); self::assertStringContainsString(