DDLRunnable::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
namespace Kir\MySQL\Builder\Internal;
3
4
use Kir\MySQL\Database\DatabaseStatement;
5
6
/**
7
 * @template T
8
 */
9
class DDLRunnable {
10
	/** @var DatabaseStatement */
11
	private $query;
12
	/** @var null|callable(scalar=): T */
13
	private $callbackFn;
14
15
	/**
16
	 * @param DatabaseStatement $query
17
	 * @param null|callable(scalar=): T $callbackFn
18
	 */
19
	public function __construct(DatabaseStatement $query, ?callable $callbackFn = null) {
20
		$this->query = $query;
21
		$this->callbackFn = $callbackFn;
22
	}
23
24
	/**
25
	 * @param array<string, mixed> $params
26
	 * @return T|int
27
	 */
28
	public function run(array $params = []) {
29
		$this->query->execute($params);
30
		$response = $this->query->getStatement()->rowCount();
31
		if($this->callbackFn !== null) {
32
			$response = call_user_func($this->callbackFn, $response);
33
		}
34
		return $response;
35
	}
36
}
37