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()); }