Passed
Push — master ( 48f23f...3d04cc )
by Jean-Christophe
07:46 queued 13s
created

BulkDeletes::addInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Ubiquity\orm\bulk;
4
5
use Ubiquity\orm\OrmUtils;
6
7
/**
8
 * Ubiquity\orm\bulk$BulkDeletes
9
 * This class is part of Ubiquity
10
 *
11
 * @author jcheron <[email protected]>
12
 * @version 1.0.0
13
 *
14
 */
15
class BulkDeletes extends AbstractBulks {
16
17
	public function addInstance($instance, $id = null) {
18
		$id = $id ?? OrmUtils::getFirstKeyValue ( $instance );
19
		$this->instances [$id] = $instance;
20
	}
21
22
	public function createSQL() {
23
		$quote = $this->db->quote;
24
		$tableName = OrmUtils::getTableName ( $this->class );
25
		$this->parameters = \array_keys ( $this->instances );
26
		$count = \count ( $this->parameters );
27
28
		return "DELETE FROM {$quote}{$tableName}{$quote} WHERE {$quote}{$this->pkName}{$quote} IN (" . \implode ( ',', \array_fill ( 0, $count, '?' ) ) . ')';
29
	}
30
}
31
32