classFormatter
final class Formatter
Restricted visibility: declared "@visibility SqlFormatter". Code outside that scope must not name this declaration.
Formats and verifies SQL using injected parsing and formatting contracts.
Methods§
public function __construct(
private SqlParser $parser,
private Dialect $dialect,
private FormatOptions $options = new \SqlFormatter\Core\FormatOptions(),
)Reuses a configured parser and an immutable layout preset across calls.
Parameters
$parser | SqlParser | |
$dialect | Dialect | |
$options | FormatOptions |
Calls 1
- new FormatOptions line 26
public function format(string $sql): stringParameters
$sql | string |
Returns
stringThrows
SourceException When the input is not accepted by the selected grammarFormattingException When output verification detects changed syntaxTest cases 3
Called from 1
Calls 11
- method-call SqlParser::parse() line 36
- class-const Style::Compact() line 37
- method-call Renderer::render() line 38
- new Renderer line 38
- method-call Dialect::compactRules() line 38
- method-call Renderer::render() line 40
- new Renderer line 40
- static-call Document::from() line 40
- method-call Dialect::syntaxRules() line 40
- new FormattingException line 44
- static-call Fingerprint::of() line 46
Private surface 3§
Implementation details, listed for orientation only.
private SqlParser $parserprivate Dialect $dialectprivate FormatOptions $options = new \SqlFormatter\Core\FormatOptions()Test cases 37§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 35
DocumentTestcallsGroupingTestcallsKeywordsTestcallsReductionsTestcallsRendererTestcallsRulesTestcallsSettingsTestcallsShapeTestcallsSpacingTestcallsTriviaTestcallsVisitorTestcallsDialectTest::testCompactRulesCanProvideAnIndependentGrammarcallsDialectTest::testSyntaxRulesCanProvideAnIndependentGrammarcallsFormatOptionsTestcallsFormattingExceptionTestcallsBlockTestcallsElementsTestcallsHeadersTestcallsPolicyTestcallsRendererTestcallsSpacingTestcallsWriterTestcallsStyleTestcallsAnalyzerTestcallsBracketsTestcallsDocumentTestcallsExpressionsTestcallsFingerprintTestcallsHeadersTestcallsListsTestcallsMarkersTestcallsRulesTestcallsDialectTestcallsDialectTestcallsDialectTestcalls
Relations§
Instantiated in 4
- new SqlCatalog\Platform\MySql\SqlFormatter::format() packages/sql-catalog/src/Platform/MySql/SqlFormatter.php:30
- new SqlCatalog\Platform\PostgreSql\SqlFormatter::format() packages/sql-catalog/src/Platform/PostgreSql/SqlFormatter.php:30
- new SqlCatalog\Platform\Sqlite\SqlFormatter::format() packages/sql-catalog/src/Platform/Sqlite/SqlFormatter.php:30
- new SqlFormatter\Facade\Formatter::__construct() packages/sql-formatter/src/Facade/Formatter.php:33
Method calls 1
Type declarations 4
- type SqlCatalog\Platform\MySql\SqlFormatter packages/sql-catalog/src/Platform/MySql/SqlFormatter.php:23
- type SqlCatalog\Platform\PostgreSql\SqlFormatter packages/sql-catalog/src/Platform/PostgreSql/SqlFormatter.php:23
- type SqlCatalog\Platform\Sqlite\SqlFormatter packages/sql-catalog/src/Platform/Sqlite/SqlFormatter.php:23
- type SqlFormatter\Facade\Formatter packages/sql-formatter/src/Facade/Formatter.php:23