Test Failed
Push — master ( c0e89d...162d08 )
by Julien
04:29
created

Mysql::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Db\Dialect;
12
13
/**
14
 * Class MySQL
15
 * - Registering custom functions
16
 * -- Regexp: " %s REGEXP $s"
17
 * -- Distance:
18
 *
19
 * @author Julien Turbide <[email protected]>
20
 * @copyright Zemit Team <[email protected]>
21
 *
22
 * @since 1.0
23
 * @version 1.0
24
 *
25
 * @package Zemit\Db\Dialect
26
 */
27
class Mysql extends \Phalcon\Db\Dialect\Mysql
28
{
29
30
    public function __construct()
31
    {
32
        $this->registerRegexpFunction();
33
        $this->registerDistanceSphereFunction();
34
        $this->registerPointFunction();
35
    }
36
    
37
    /**
38
     * Register Regexp function
39
     * @return void
40
     */
41
    public function registerRegexpFunction() {
42
        $this->registerCustomFunction('regexp', function($dialect, $expression) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
43
            $arguments = $expression['arguments'];
44
            return sprintf(
45
                " %s REGEXP %s",
46
                $dialect->getSqlExpression($arguments[0]),
47
                $dialect->getSqlExpression($arguments[1])
48
            );
49
        });
50
    }
51
    
52
    /**
53
     * Register ST_Distance_Sphere function
54
     * @return void
55
     */
56
    public function registerDistanceSphereFunction() {
57
        $this->registerCustomFunction('ST_Distance_Sphere', function($dialect, $expression) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
58
            $arguments = $expression['arguments'];
59
            return sprintf(
60
                " ST_Distance_Sphere(%s, %s)",
61
                $dialect->getSqlExpression($arguments[0]),
62
                $dialect->getSqlExpression($arguments[1]),
63
            );
64
        });
65
    }
66
    
67
    /**
68
     * Register ST_Distance_Sphere function
69
     * @return void
70
     */
71
    public function registerPointFunction() {
72
        $this->registerCustomFunction('point', function($dialect, $expression) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
73
            $arguments = $expression['arguments'];
74
            return sprintf(
75
                " point(%s, %s)",
76
                $dialect->getSqlExpression($arguments[0]),
77
                $dialect->getSqlExpression($arguments[1]),
78
            );
79
        });
80
    }
81
    
82
}
83