Passed
Push — master ( 87e63f...d6a1bd )
by Darío
02:40
created

SQLFunction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * DronePHP (http://www.dronephp.com)
4
 *
5
 * @link      http://github.com/Pleets/DronePHP
6
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
7
 * @license   http://www.dronephp.com/license
8
 * @author    Darío Rivera <[email protected]>
9
 */
10
11
namespace Drone\Db;
12
13
/**
14
 * SQLFunction class
15
 *
16
 * This class could be used to build specific querys that requires
17
 * specific database functions that data mapper does not support
18
 */
19
class SQLFunction
20
{
21
    /**
22
     * The SQL function name
23
     *
24
     * @var string
25
     */
26
    private $function;
27
28
    /**
29
     * The arguments for the SQL function
30
     *
31
     * @var array
32
     */
33
    private $arguments;
34
35
    /**
36
     * Returns the SQL function
37
     *
38
     * @return string
39
     */
40
    public function getFunction()
41
    {
42
        return $this->function;
43
    }
44
45
    /**
46
     * Returns the arguments for the SQL function
47
     *
48
     * @return array
49
     */
50
    public function getArguments()
51
    {
52
        return $this->arguments;
53
    }
54
55
    /**
56
     * Constructor
57
     *
58
     * @param string $function
59
     * @param array $args
60
     *
61
     * @return null
62
     */
63 2
    public function __construct($function, Array $args)
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected array, but found Array.
Loading history...
64
    {
65 2
        $this->function  = $function;
66 2
        $this->arguments = $args;
67 2
    }
68
69
    /**
70
     * Returns the SQL statment
71
     *
72
     * @return string
73
     */
74 2
    public function getStatement()
75
    {
76 2
        $arguments = $this->arguments;
77
78 2
        foreach ($arguments as $key => $arg)
79
        {
80 2
            if (is_string($arg))
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
81 2
                $arguments[$key] = "'$arg'";
82
        }
83
84 2
        $arguments = implode(", ", array_values($arguments));
85
86 2
        return $this->function . '(' . $arguments . ')';
87
    }
88
}