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

Cast   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A customiseFunction() 0 5 1
A getSql() 0 6 1
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