ConditionAddHelper::addAsArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace Kir\MySQL\Builder\Helpers;
4
5
use Kir\MySQL\Builder\Expr\OptionalExpression;
6
use Kir\MySQL\Builder\Internal\Types;
7
use Kir\MySQL\Builder\Traits\WhereBuilder;
8
9
/**
10
 * @phpstan-import-type DBParameterValueType from Types
11
 * @phpstan-import-type DBWhereExpressionType from WhereBuilder
12
 */
13
abstract class ConditionAddHelper {
14
	/**
15
	 * @param callable(string|array<string, null|scalar>, array<int, DBParameterValueType>): void $addFn
16
	 * @param DBWhereExpressionType $expression
0 ignored issues
show
Bug introduced by
The type Kir\MySQL\Builder\Helpers\DBWhereExpressionType 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...
17
	 * @param array<DBParameterValueType> $args
18
	 */
19
	public static function addCondition(callable $addFn, $expression, array $args): void {
20
		if($expression instanceof OptionalExpression) {
21
			if($expression->isValid()) {
22
				$addFn($expression->getExpression(), [$expression->getValue()]);
23
			}
24
		} elseif(is_object($expression)) {
25
			self::addAsArray($addFn, (array) $expression, $args);
26
		} elseif(is_array($expression)) {
27
			self::addAsArray($addFn, $expression, $args);
28
		} else {
29
			$addFn($expression, $args);
30
		}
31
	}
32
33
	/**
34
	 * @param callable(string|array<string, mixed>, array<int, mixed>): void $addFn
35
	 * @param array<string, mixed> $expression
36
	 * @param array<int, DBParameterValueType> $args
37
	 */
38
	private static function addAsArray(callable $addFn, array $expression, array $args): void {
39
		if(count($expression) > 0) {
40
			$addFn($expression, $args);
41
		}
42
	}
43
}
44