Issues (83)

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
	/** @var Database */
11
	private $db;
12
	/** @var AliasReplacer */
13
	private $aliasReplacer;
14
	/** @var array<string, mixed> */
15
	private $options;
16
17
	/**
18
	 * @param Database $db
19
	 * @param array<string, mixed> $options
20
	 */
21
	public function __construct($db, array $options = []) {
22
		$this->db = $db;
23
		$this->aliasReplacer = new AliasReplacer($db->getAliasRegistry());
24
		$this->options = $options;
25
	}
26
27
	/**
28
	 * @param bool $stop
29
	 * @return $this
30
	 */
31
	public function debug($stop = true) {
32
		if(array_key_exists('debug_formatter', $this->options)) {
33
			$this->options['debug_formatter']();
34
		} elseif(PHP_SAPI === 'cli') {
35
			echo "\n{$this->__toString()}\n";
36
		} else {
37
			echo "<pre>{$this->__toString()}</pre>";
38
		}
39
		if($stop) {
40
			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...
41
		}
42
		return $this;
43
	}
44
45
	/**
46
	 * @return Statement
47
	 */
48
	public function cloneStatement(): Statement {
49
		return clone $this;
50
	}
51
52
	/**
53
	 * @return AliasReplacer
54
	 */
55
	public function aliasReplacer(): AliasReplacer {
56
		return $this->aliasReplacer;
57
	}
58
59
	/**
60
	 * @return Database
61
	 */
62
	protected function db() {
63
		return $this->db;
64
	}
65
66
	/**
67
	 * @return string
68
	 */
69
	abstract public function __toString(): string;
70
}
71