classStatement
final class Statement
uses Assertion
Public API: explicitly declared with
@visibility public.A complete SQL command whose values are independent of parsing.
Fixed syntax is defined by the concrete value classes. Arguments are named fields, finite options are enums, and forwarding grammar rules are removed. No source string, parser node, token, or construction map is retained. Comments written before the command or after it belong to the statement, so they survive when the command is replaced.
$statement = (new \SqlSemantics\Facade\Semantics(\SqlSemantics\Platform\Sqlite\Dialect::Sqlite))->analyze('SELECT 1');
str_contains($statement->toString(), 'SELECT') // => true$statement = (new \SqlSemantics\Facade\Semantics(\SqlSemantics\Platform\Sqlite\Dialect::Sqlite))->analyze('SELECT 1 -- audited');
$statement->withCommand($statement->command)->toString() // => "SELECT 1 -- audited"Constants§
public const BEFORE = 0The comment position before the command.
public const AFTER = 1The comment position after the command.
Properties§
public Command $commandpublic Comments $comments = new \SqlSemantics\Statement\Comments()Methods§
public function __construct(
public Command $command,
public Comments $comments = new \SqlSemantics\Statement\Comments(),
)Supplies the complete command value and the comments written around it.
Parameters
Calls 7
- new Comments line 43
- method-call Statement::assertImmutableValueGraph() line 45
- method-call Statement::assert() line 46
- function-call
array_diffline 46 - method-call Comments::positions() line 46
- class-const Statement::BEFORE() line 46
- class-const Statement::AFTER() line 46
public function withCommand(Command $command): selfpublic function withComments(Comments $comments): selfpublic function toString(): stringReconstructs SQL solely from the command's fields, options, and comments.
Returns
stringTest cases 9
ValueReaderTest::testFromFileLoadsTheDatabasePackageVocabularycallsValueReaderTest::testReadReleasesParserObjectsAfterLoweringcallsPlatformTest::testValuesReconstructsUsingTheParserReleasecallsPlatformTest::testValuesReconstructsUsingTheParserReleasecallsCommandTest::testWriteWithCompleteCommandcallsStatementTest::testToStringUsesIndependentlyConstructedDatacallsStatementTest::testWithCommandConstructsAndUpdatesWithoutLoadingTheSqlParsercallsStatementTest::testWithCommandSharesUnchangedValuesAndPreservesTheOriginalcallsStatementTest::testWithCommentsReplacesTheCommentsAroundTheSameCommandcalls
Calls 6
- new Writer line 70
- method-call Writer::comments() line 71
- class-const Statement::BEFORE() line 71
- method-call Command::write() line 72
- class-const Statement::AFTER() line 73
- method-call Writer::toString() line 75
Test cases 16§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
StatementTest::testToStringUsesIndependentlyConstructedDatacallsStatementTest::testWithCommandConstructsAndUpdatesWithoutLoadingTheSqlParsercallsStatementTest::testWithCommandKeepsTheCommentsAroundTheCommandcallsStatementTest::testWithCommandSharesUnchangedValuesAndPreservesTheOriginalcallsStatementTest::testWithCommentsReplacesTheCommentsAroundTheSameCommandcalls
Other tests reaching this symbol 11
AnalyzerTestcallsValueReaderTest::testFromFileLoadsTheDatabasePackageVocabularycallsValueReaderTest::testReadReleasesParserObjectsAfterLoweringcallsValueReaderTest::testStatementGivesTheOuterCommentsToTheStatementAndTheInnerOnesToValuescallsAnalysisExceptionTestcallsPlatformTest::testValuesReconstructsUsingTheParserReleasecallsSemanticsTestcallsPlatformTest::testValuesReconstructsUsingTheParserReleasecallsCommandTest::testWriteWithCompleteCommandcallsElementTestcallsWriterTestcalls