Issues (85)

src/Builder/Statement.php (1 issue)

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