Passed
Pull Request — master (#116)
by Martin
01:51
created

Cast::customiseFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\SqlWalker;
8
9
/**
10
 * Implementation of PostgreSql CAST().
11
 *
12
 * @see https://www.postgresql.org/docs/current/sql-createcast.html
13
 * @since 1.8.0
14
 */
15
class Cast extends BaseFunction
16
{
17
    protected function customiseFunction(): void
18
    {
19
        $this->setFunctionPrototype('cast(%s AS %s)');
20
        $this->addNodeMapping('StringPrimary');
21
        $this->addNodeMapping('StringPrimary');
22
    }
23
24
    public function getSql(SqlWalker $sqlWalker): string
25
    {
26
        $sql = parent::getSql($sqlWalker);
27
28
        // Remove the quotes around the target type
29
        return preg_replace('#AS \'(\w+)\'#', 'AS $1', $sql);
30
    }
31
}
32