DDLRunnable::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
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