From 46136151930b2f647d57bbc7cb790ae60ac36ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammet=20=C5=9Eafak?= Date: Sun, 24 May 2026 21:20:06 +0300 Subject: [PATCH] Allow phpcs ^4.0 and phpstan ^2.0; remove RawQuery::get null-coalesce --- composer.json | 4 ++-- src/RawQuery.php | 6 ++++-- tests/RawQueryTest.php | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 0bc0257..9fc025d 100644 --- a/composer.json +++ b/composer.json @@ -34,8 +34,8 @@ }, "require-dev": { "phpunit/phpunit": "^10.5", - "squizlabs/php_codesniffer": "^3.10", - "phpstan/phpstan": "^1.12" + "squizlabs/php_codesniffer": "^3.10 || ^4.0", + "phpstan/phpstan": "^1.12 || ^2.0" }, "scripts": { "test": "phpunit", diff --git a/src/RawQuery.php b/src/RawQuery.php index 47b93b4..ddc3ebc 100644 --- a/src/RawQuery.php +++ b/src/RawQuery.php @@ -64,11 +64,13 @@ public function set(mixed $rawQuery): self } /** - * The stored SQL fragment (empty string if never set). + * The stored SQL fragment. The constructor always calls {@see self::set()}, + * which always assigns `$this->raw` in every branch, so the property is + * guaranteed to be initialised by the time this getter runs. */ public function get(): string { - return $this->raw ?? ''; + return $this->raw; } /** diff --git a/tests/RawQueryTest.php b/tests/RawQueryTest.php index 3f9354e..be4fb71 100644 --- a/tests/RawQueryTest.php +++ b/tests/RawQueryTest.php @@ -63,11 +63,12 @@ public function testMixedInputIsCastToString(): void $this->assertSame('42', (string) $raw); } - public function testGetReturnsEmptyStringByDefault(): void + public function testGetReturnsEmptyStringWhenConstructedWithEmptyString(): void { - // The constructor always calls set(), so this only exercises the - // null-coalesce fall-back inside get() — useful when subclasses - // bypass set(). + // The constructor calls set(''), which assigns the empty string to + // $this->raw. The previous null-coalesce fall-back in get() was + // unreachable defensive code — PHPStan 2.x correctly flagged it, + // and it was removed. $raw = new RawQuery(''); $this->assertSame('', $raw->get()); }