SQL   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A query() 0 13 3
1
<?php
2
3
/**
4
 * If finder class is not powerful enough use this one
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Datamapper
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\datamapper;
17
18
/**
19
 * If finder class is not powerful enough use this one
20
 *
21
 * @category  Core
22
 * @package   Datamapper
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class SQL
30
{
31
    /**
32
     * Database service object
33
     **/
34
    private $_database = null;
35
36
    /**
37
     * Prepare values that are needed for later usage
38
     *
39
     * @return \csphere\core\datamapper\SQL
40
     **/
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
41
42
    public function __construct()
43
    {
44
        // Get database service object
45
        $loader = \csphere\core\service\Locator::get();
46
47
        $this->_database = $loader->load('database');
48
    }
49
50
    /**
51
     * Send direct SQL requests to the database
52
     *
53
     * @param string  $prepare Prepared query string with placeholders
54
     * @param array   $assoc   Array with columns and values
55
     * @param integer $first   Number of the first dataset to show
56
     * @param integer $max     Number of datasets to show from first on
57
     *
58
     * @return array
59
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
60
61
    public function query($prepare, array $assoc, $first = 0, $max = 1)
62
    {
63
        // Pass query to database driver
64
        $result = $this->_database->query($prepare, $assoc, $first, $max);
65
66
        // Handle array dimension for max=1 since db layer uses fetch for that case
67
        if ($max == 1 && $result != []) {
68
69
            $result = [$result];
70
        }
71
72
        return $result;
73
    }
74
}
75