Passed
Push — master ( 42827c...afb1ed )
by Jean-Christophe
11:19
created

DAOPreparedQueryById   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
eloc 22
c 4
b 0
f 1
dl 0
loc 32
ccs 24
cts 26
cp 0.9231
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 4
A prepare() 0 5 1
A __construct() 0 2 1
1
<?php
2
3
namespace Ubiquity\orm\core\prepared;
4
5
use Ubiquity\events\DAOEvents;
6
use Ubiquity\events\EventsManager;
7
use Ubiquity\orm\DAO;
8
use Ubiquity\orm\OrmUtils;
9
10
/**
11
 * Ubiquity\orm\core\prepared$DAOPreparedQueryOne
12
 * This class is part of Ubiquity
13
 *
14
 * @author jcheron <[email protected]>
15
 * @version 1.0.1
16
 *
17
 */
18
class DAOPreparedQueryById extends DAOPreparedQuery {
19
20 28
	public function __construct($className, $included = false) {
21 28
		parent::__construct ( $className, '', $included );
22 28
	}
23
24 28
	protected function prepare() {
25 28
		parent::prepare ();
26 28
		$keys = OrmUtils::getKeyFields ( $this->className );
27 28
		$this->conditionParser->addKeyValues ( \array_fill ( 0, \count ( $keys ), '' ), $this->className );
28 28
		$this->conditionParser->limitOne ();
29 28
	}
30
31 1
	public function execute($params = [ ], $useCache = false) {
32 1
		$cp = $this->conditionParser;
33 1
		$cp->setKeyValues ( $params );
34 1
		$query = $this->db->prepareAndExecute ( $this->tableName, $this->preparedCondition, $this->fieldList . $this->sqlAdditionalMembers, $cp->getParams (), $useCache );
35 1
		if ($query && \sizeof ( $query ) > 0) {
36 1
			$oneToManyQueries = [ ];
37 1
			$manyToOneQueries = [ ];
38 1
			$manyToManyParsers = [ ];
39 1
			$className = $this->className;
40 1
			$row = \current ( $query );
41 1
			$object = DAO::_loadObjectFromRow ( $this->db, $row, $className, $this->invertedJoinColumns, $manyToOneQueries, $this->oneToManyFields, $this->manyToManyFields, $oneToManyQueries, $manyToManyParsers, $this->accessors, $this->transformers );
42 1
			$this->addAditionnalMembers ( $object, $row );
43 1
			if ($this->hasIncluded) {
44
				DAO::_affectsRelationObjects ( $className, $this->firstPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, [ $object ], $this->included, $useCache );
45
			}
46 1
			EventsManager::trigger ( DAOEvents::GET_ONE, $object, $className );
47 1
			return $object;
48
		}
49
		return null;
50
	}
51
}
52