Lines 100.00% 18 / 18
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 quoteTable 100.00% 1 / 1 100.00% 1 / 1 1
 quoteField 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsbackend\Query\Builder\Dialect\Quote] quoteStructureParts 100.00% 16 / 16 100.00% 1 / 1 10
16class MySQL implements DialectInterface
17{
18    use Quote;
19
20    /**
21     * Quotes a table name correctly as per this engines dialect.
22     *
23     * @param   string $table
24     * @return  string
25     */
26    #[\Override]
27    public function quoteTable($table)
28    {
29        return $this->quoteStructureParts($table, '`');
30    }
31
32    /**
33     * Correctly quotes a field name, either in "name" or "table.name" format.
34     *
35     * @param   string $field
36     * @return  string
37     */
38    #[\Override]
39    public function quoteField($field)
40    {
41        return $this->quoteStructureParts($field, '`', ['*']);
42    }
43}

From BO\Zmsbackend\Query\Builder\Dialect\Quote

18trait Quote
19{
20    /**
21     * Takes a period-separated string and puts the appropriate quote
22     * marks around it, guarding against double quoting.
23     *
24     * @param   string|ExpressionInterface  $string
25     * @param   string                      $quoteMark      Mark to use for start and end of quotes
26     * @param   array                       $unquotable     Any strings that mustn't be quoted (ie *)
27     * @return  string
28     */
29    protected function quoteStructureParts($string, $quoteMark, array $unquotable = [])
30    {
31        if ($string instanceof ExpressionInterface) {
32            return $string;
33        }
34
35        if ($string === null || strlen($string = trim($string)) === 0) {
36            return $string;
37        }
38
39        $parts = explode('.', $string);
40        $rebuild = [];
41        foreach ($parts as $p) {
42            $p = trim($p);
43            if (!in_array($p, $unquotable) && $p != '') {
44                // quote at the front
45                if (strpos($p, $quoteMark) !== 0) {
46                    $p = $quoteMark . $p;
47                }
48                // quote at the back:
49                if (strrpos($p, $quoteMark) != (strlen($p) - 1)) {
50                    $p .= $quoteMark;
51                }
52            }
53
54            if (trim($p) != '') {
55                $rebuild[] = $p;
56            }
57        }
58
59        return implode('.', $rebuild);
60    }
61}