Completed
Push — master ( 144202...6a00f8 )
by Peter
11:59
created

DataTrait::getData()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 9
cp 0.8889
rs 9.2
cc 4
eloc 6
nc 4
nop 1
crap 4.0218
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Traits\DataProvider;
10
11
/**
12
 * DataTrait
13
 *
14
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
15
 */
16
trait DataTrait
17
{
18
19
	private $data = null;
20
21
	/**
22
	 * Returns the data items currently available, ensures that result is at leas empty array
23
	 * @param boolean $refresh whether the data should be re-fetched from persistent storage.
24
	 * @return array the list of data items currently available in this data provider.
25
	 */
26 1
	public function getData($refresh = false)
27
	{
28 1
		if ($this->data === null || $refresh)
29 1
		{
30 1
			$this->data = $this->fetchData();
31 1
		}
32 1
		if ($this->data === null)
33 1
		{
34
			return [];
35
		}
36 1
		return $this->data;
37
	}
38
39
	abstract protected function fetchData();
40
}
41