Completed
Push — master ( 9f8cbf...ebe6f0 )
by Sébastien
16:49 queued 08:42
created

AbstractSource   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 2
cbo 1
dl 0
loc 128
ccs 23
cts 23
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
loadDefaultColumnModel() 0 1 ?
getMetadataReader() 0 1 ?
A getOptions() 0 7 2
getData() 0 1 ?
A setIdentifier() 0 4 1
A getIdentifier() 0 4 1
A hasColumnModel() 0 4 1
A getColumnModel() 0 7 2
A setColumnModel() 0 5 1
A setMetadataReader() 0 4 1
1
<?php
2
/**
3
 *
4
 * @author Vanvelthem Sébastien
5
 */
6
namespace Soluble\FlexStore\Source;
7
8
use Soluble\FlexStore\Options;
9
use Soluble\Metadata\Reader\AbstractMetadataReader;
10
use Soluble\FlexStore\Column\ColumnModel;
11
12
abstract class AbstractSource implements SourceInterface
13
{
14
    /**
15
     * @var \Soluble\FlexStore\Options
16
     */
17
    protected $options;
18
19
20
    /**
21
     * Column model
22
     * @var ColumnModel
23
     */
24
    protected $columnModel;
25
26
    /**
27
     * @var string|int
28
     */
29
    protected $identifier;
30
31
32
    /**
33
     *
34
     * @var AbstractMetadataReader
35
     */
36
    protected $metadataReader;
37
38
39
    /**
40
     *
41
     * @return \Soluble\FlexStore\Options
42
     */
43 34
    public function getOptions()
44
    {
45 34
        if ($this->options === null) {
46 34
            $this->options = new Options();
47 34
        }
48 34
        return $this->options;
49
    }
50
51
52
    /**
53
     *
54
     * @param Options $options
55
     * @return \Soluble\FlexStore\ResultSet\ResultSet
56
     */
57
    abstract public function getData(Options $options = null);
58
59
    /**
60
     * Set the primary key / unique identifier in the store
61
     *
62
     * @param string|null $identifier column name of the primary key
63
     * @return AbstractSource
64
     */
65 1
    public function setIdentifier($identifier)
66
    {
67 1
        $this->identifier = $identifier;
68 1
    }
69
70
    /**
71
     * Return the primary key / unique identifier in the store
72
     * Null if not applicable
73
     *
74
     * @return string|null
75
     */
76 1
    public function getIdentifier()
77
    {
78 1
        return $this->identifier;
79
    }
80
81
82
    /**
83
     * Whether a column model exists
84
     *
85
     * @return boolean
86
     */
87 25
    public function hasColumnModel()
88
    {
89 25
        return ($this->columnModel !== null);
90
    }
91
92
    /**
93
     * Return column model
94
     *
95
     * @return ColumnModel
96
     */
97 30
    public function getColumnModel()
98
    {
99 30
        if ($this->columnModel === null) {
100 30
            $this->loadDefaultColumnModel();
101 30
        }
102 30
        return $this->columnModel;
103
    }
104
105
    /**
106
     * Set column model associated with the datasource
107
     *
108
     * @param ColumnModel $columnModel
109
     * @return AbstractSource
110
     */
111 30
    public function setColumnModel(ColumnModel $columnModel)
112
    {
113 30
        $this->columnModel = $columnModel;
114 30
        return $this;
115
    }
116
117
118
    /**
119
     * Default column model initialization
120
     */
121
    abstract public function loadDefaultColumnModel();
122
123
124
    /**
125
     * Set underlying metadatareader
126
     * @param AbstractMetadataReader $metadataReader
127
     */
128 32
    public function setMetadataReader(AbstractMetadataReader $metadataReader)
129
    {
130 32
        $this->metadataReader = $metadataReader;
131 32
    }
132
133
    /**
134
     * Return underlying metadata reader
135
     *
136
     * @return AbstractMetadataReader
137
     */
138
    abstract public function getMetadataReader();
139
}
140