packages/sql-semantics-postgres/src/Statement/Expression/Problem/NoCollation.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Expression\Problem;
6
7use SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic;
8use SqlSemantics\Platform\PostgreSql\Model\Statement\Snapshot;
9
10/**
11 * A collation applied to a value of a type without collation support.
12 *
13 * Source: https://www.postgresql.org/docs/17/collation.html.
14 *
15 * @visibility public
16 * @example Reading the message
17 *     (new \SqlSemantics\Platform\PostgreSql\Statement\Expression\Problem\NoCollation('integer'))->message() // => 'Collations are not supported by type integer.'
18 */
19final class NoCollation implements Diagnostic
20{
21    use Snapshot;
22
23    /**
24     * @param string $type The type of the value
25     */
26    public function __construct(public readonly string $type)
27    {
28    }
29
30    /**
31     * Describes the problem.
32     */
33    public function message(): string
34    {
35        return 'Collations are not supported by type ' . $this->type . '.';
36    }
37}
38