AbstractSource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 0
loc 126
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

10 Methods

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