Passed
Push — master ( 99686f...b494ba )
by Jean-Christophe
11:21
created

DAOPreparedTrait::prepareGetAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 5
crap 1
1
<?php
2
namespace Ubiquity\orm\traits;
3
4
use Ubiquity\orm\core\prepared\DAOPreparedQueryOne;
5
use Ubiquity\orm\core\prepared\DAOPreparedQueryById;
6
use Ubiquity\orm\core\prepared\DAOPreparedQueryAll;
7
use Ubiquity\orm\core\prepared\DAOPreparedQuery;
8
9
/**
10
 * Ubiquity\orm\traits$DAOPreparedTrait
11
 * This class is part of Ubiquity
12
 *
13
 * @author jcheron <[email protected]>
14
 * @version 1.0.0
15
 *
16
 */
17
trait DAOPreparedTrait {
18
19
	protected static $preparedDAOQueries = [];
20
21 28
	public static function prepareGetById($name, $className, $included = false, $cache = null) {
22 28
		return self::$preparedDAOQueries[$name] = new DAOPreparedQueryById($className, $included, $cache);
23
	}
24
25 28
	public static function prepareGetOne($name, $className, $condition = '', $included = false, $cache = null) {
26 28
		return self::$preparedDAOQueries[$name] = new DAOPreparedQueryOne($className, $condition, $included, $cache);
27
	}
28
29 28
	public static function prepareGetAll($name, $className, $condition = '', $included = false, $cache = null) {
30 28
		return self::$preparedDAOQueries[$name] = new DAOPreparedQueryAll($className, $condition, $included, $cache);
31
	}
32
33 1
	public static function executePrepared($name, $params = [], $useCache = false) {
34 1
		if (isset(self::$preparedDAOQueries[$name])) {
35 1
			return self::$preparedDAOQueries[$name]->execute($params, $useCache);
36
		}
37
		return null;
38
	}
39
40
	public static function storeDbCachePrepared($name) {
41
		if (isset(self::$preparedDAOQueries[$name])) {
42
			self::$preparedDAOQueries[$name]->storeDbCache();
43
		}
44
	}
45
46
	/**
47
	 * Returns the daoPreparedQuery corresponding to a name
48
	 *
49
	 * @param string $name
50
	 * @return DAOPreparedQuery
51
	 */
52 1
	public static function getPrepared(string $name): DAOPreparedQuery {
53 1
		return self::$preparedDAOQueries[$name];
54
	}
55
}
56
57