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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/RawQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions tests/RawQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Loading