Base::__construct()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Provides a layer for persistency
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
 * Provides a layer for persistency
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
abstract class Base
30
{
31
    /**
32
     * Database service object
33
     **/
34
    protected $database = null;
35
36
    /**
37
     * Name of target plugin
38
     **/
39
    protected $plugin;
40
41
    /**
42
     * Name of plugin table
43
     **/
44
    protected $table;
45
46
    /**
47
     * Name of ID column in that table
48
     **/
49
    protected $serial;
50
51
    /**
52
     * Combination of plugin and table that is generated automatically
53
     **/
54
    protected $schema;
55
56
    /**
57
     * Construction details of schema
58
     **/
59
    protected $structure;
60
61
    /**
62
     * Construction details of schema
63
     **/
64
    protected $joins = [];
65
66
    /**
67
     * Prepare values that are needed for later usage
68
     *
69
     * @param string $plugin Plugin name
70
     * @param string $table  Table name without plugin_ prefix
71
     *
72
     * @return \csphere\core\datamapper\Base
73
     **/
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...
74
75
    public function __construct($plugin, $table = '')
76
    {
77
        // Get database service object
78
        $loader = \csphere\core\service\Locator::get();
79
80
        $this->database = $loader->load('database');
81
82
        // Set plugin, table and schema to work with
83
        $this->plugin = $plugin;
84
        $this->table  = $table;
85
86
        $this->schema = $plugin;
87
88
        if ($this->table != '') {
89
90
            $this->schema .= '_' . $this->table;
91
        }
92
93
        // Load schema details, e.g. for creating new entries
94
        $this->structure = \csphere\core\datamapper\Schema::load(
95
            $this->plugin, $this->table
96
        );
97
98
        $this->serial = $this->structure['serial'];
99
    }
100
101
    /**
102
     * Name of serial column in this table
103
     *
104
     * @return string
105
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
106
107
    public function serial()
108
    {
109
        return $this->serial;
110
    }
111
}
112