Delete::from()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Kir\MySQL\Builder;
4
5
use Kir\MySQL\Builder\Internal\Types;
6
use Kir\MySQL\Builder\Traits\JoinBuilder;
7
use Kir\MySQL\Builder\Traits\LimitBuilder;
8
use Kir\MySQL\Builder\Traits\OffsetBuilder;
9
use Kir\MySQL\Builder\Traits\OrderByBuilder;
10
use Kir\MySQL\Builder\Traits\TableBuilder;
11
use Kir\MySQL\Builder\Traits\TableNameBuilder;
12
use Kir\MySQL\Builder\Traits\WhereBuilder;
13
14
/**
15
 * @phpstan-import-type DBTableNameType from Types
16
 */
17
abstract class Delete extends Statement {
18
	use TableNameBuilder;
19
	use TableBuilder;
20
	use JoinBuilder;
21
	use WhereBuilder;
22
	use OrderByBuilder;
23
	use LimitBuilder;
24
	use OffsetBuilder;
25
26
	/** @var string[] */
27
	private array $aliases = [];
28
29
	/**
30
	 * Name der Tabelle
31
	 *
32
	 * @param ($table is null ? DBTableNameType : string) $alias
0 ignored issues
show
Bug introduced by
The type Kir\MySQL\Builder\is was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
	 * @param null|DBTableNameType $table
0 ignored issues
show
Bug introduced by
The type Kir\MySQL\Builder\DBTableNameType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
	 * @return $this
35
	 */
36
	public function from($alias, $table = null) {
37
		if($table !== null) {
38
			$this->aliases[] = $alias;
39
		}
40
		if($table === null) {
41
			[$alias, $table] = [$table, $alias];
42
		}
43
		$this->addTable($alias, $table);
44
45
		return $this;
46
	}
47
48
	/**
49
	 * @param array<string, mixed> $params
50
	 * @return int
51
	 */
52
	abstract public function run(array $params = []);
53
54
	/**
55
	 * @return string
56
	 */
57
	public function __toString(): string {
58
		$query = 'DELETE ';
59
		$query .= implode(', ', $this->aliases);
60
		$query = trim($query) . " FROM\n";
61
		$query = $this->buildTables($query);
62
		$query = $this->buildJoins($query);
63
		$query = $this->buildWhereConditions($query);
64
		$query = $this->buildOrder($query);
65
		$query = $this->buildLimit($query);
66
		$query = $this->buildOffset($query);
67
68
		return $query;
69
	}
70
}
71