packages/sql-semantics-mysql/src/Statement/Utility/Problem/UtilityMisuse.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Utility\Problem;
6
7use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
8use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
9
10/**
11 * A rule of SET, SHOW or EXPLAIN the statement breaks, which the server would refuse.
12 *
13 * @visibility public
14 * @example Reading the message of a refused format
15 *     (new \SqlSemantics\Platform\MySql\Semantics())->analyze('EXPLAIN FORMAT = yaml SELECT 1') // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\SemanticException: Unknown EXPLAIN format name
16 */
17final class UtilityMisuse implements Diagnostic
18{
19    use Snapshot;
20
21    /**
22     * @param UtilityRule $rule The broken rule
23     */
24    public function __construct(public readonly UtilityRule $rule)
25    {
26    }
27
28    /**
29     * Describes the broken rule in the words of the server.
30     */
31    public function message(): string
32    {
33        return $this->rule->value;
34    }
35}
36