Statement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Kir\MySQL\Builder;
4
5
use Kir\MySQL\Builder\Internal\StatementInterface;
6
use Kir\MySQL\Database;
7
use Kir\MySQL\Tools\AliasReplacer;
8
9
abstract class Statement implements StatementInterface {
10
	private AliasReplacer $aliasReplacer;
11
12
	/**
13
	 * @param Database $db
14
	 * @param array<string, mixed> $options
15
	 */
16
	public function __construct(
17
		private Database $db,
18
		private array $options = [],
19
	) {
20
		$this->aliasReplacer = new AliasReplacer($db->getAliasRegistry());
21
	}
22
23
	/**
24
	 * @param bool $stop
25
	 * @return $this
26
	 */
27
	public function debug($stop = true) {
28
		if(array_key_exists('debug_formatter', $this->options)) {
29
			$this->options['debug_formatter']();
30
		} elseif(PHP_SAPI === 'cli') {
31
			echo "\n{$this->__toString()}\n";
32
		} else {
33
			echo "<pre>{$this->__toString()}</pre>";
34
		}
35
		if($stop) {
36
			exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
37
		}
38
39
		return $this;
40
	}
41
42
	/**
43
	 * @return Statement
44
	 */
45
	public function cloneStatement(): Statement {
46
		return clone $this;
47
	}
48
49
	/**
50
	 * @return AliasReplacer
51
	 */
52
	public function aliasReplacer(): AliasReplacer {
53
		return $this->aliasReplacer;
54
	}
55
56
	/**
57
	 * @return Database
58
	 */
59
	protected function db(): Database {
60
		return $this->db;
61
	}
62
63
	/**
64
	 * @return string
65
	 */
66
	abstract public function __toString(): string;
67
}
68