DDLRunnable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 2
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 2
A __construct() 0 5 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 null|callable(scalar=): T */
11
	private $callbackFn;
12
13
	/**
14
	 * @param DatabaseStatement $query
15
	 * @param null|callable(scalar=): T $callbackFn
16
	 */
17
	public function __construct(
18
		private DatabaseStatement $query,
19
		?callable $callbackFn = null
20
	) {
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