Command::isSingleStatement()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Core\SqlAction;
4
5
use Db3v4l\API\Interfaces\SqlAction\CommandAction;
6
7
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
8
 * @todo allow extraction of the statements as an array, in case we have some executors that can only work on statements...
9
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
10
class Command implements CommandAction
11
{
12
    protected $sql;
13
    protected $callable;
14
    protected $isSingleStatement;
15
    protected $statementSeparator = "\n";
16
    //protected $statementTerminator = ';';
17
18
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
     * @param string|string[]|null $sql for single statements, pass in either a string or an array with a single string element
0 ignored issues
show
Coding Style introduced by
Expected 15 spaces after parameter name; 1 found
Loading history...
20
     *                                  for multiple statements, pass in an array of strings
21
     *                                  pass in null when all you need to execute is the callable
22
     * @param callable|null $callable
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
23
     * @param bool $isSingleStatement if left null, it will be inferred
0 ignored issues
show
Coding Style introduced by
Expected 17 spaces after parameter type; 1 found
Loading history...
24
     */
25
    public function __construct($sql, $callable = null, $isSingleStatement = null)
26
    {
27
        if (is_array($sql)) {
28
            foreach ($sql as &$statement) {
29
                $statement = trim($statement);
30
                // Disabled as it messes up with mssql GO statements, which take no terminator...
31
                // @todo find a simple way to reintroduce this, while allowing support for sql comments as part of statements...
32
                //if (substr($statement, -1) !== $this->statementTerminator) {
33
                //    $statement .= $this->statementTerminator;
34
                //}
35
            }
36
            $this->sql = implode($this->statementSeparator, $sql);
37
            $isSingleStatement = ($isSingleStatement === null) ? (count($sql) < 2) : $isSingleStatement;
38
        } else {
39
            $this->sql = ($sql === null) ? $sql : trim($sql);
40
            $isSingleStatement = ($isSingleStatement === null) ? true : $isSingleStatement;
41
        }
42
        $this->callable = $callable;
43
        $this->isSingleStatement = $isSingleStatement;
44
    }
45
46
    public function getCommand()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getCommand()
Loading history...
47
    {
48
        return $this->sql;
49
    }
50
51
    public function isSingleStatement()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isSingleStatement()
Loading history...
52
    {
53
        return $this->isSingleStatement;
54
    }
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @todo should we unwrap PDOStatement into a string ?
0 ignored issues
show
Coding Style introduced by
Tag value for @todo tag indented incorrectly; expected 3 spaces but found 1
Loading history...
58
     * @return Callable|null
59
     */
60
    public function getResultsFilterCallable()
61
    {
62
        return $this->callable;
63
    }
64
}
65