0
0
mirror of https://github.com/nextcloud/server.git synced 2024-11-14 20:36:50 +00:00
nextcloud_server/lib/private/DB/QueryBuilder/CompositeExpression.php
dependabot[bot] bb598c8451
chore(deps): Bump nextcloud/coding-standard in /vendor-bin/cs-fixer
Bumps [nextcloud/coding-standard](https://github.com/nextcloud/coding-standard) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/nextcloud/coding-standard/releases)
- [Changelog](https://github.com/nextcloud/coding-standard/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nextcloud/coding-standard/compare/v1.3.1...v1.3.2)

---
updated-dependencies:
- dependency-name: nextcloud/coding-standard
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: provokateurin <kate@provokateurin.de>
2024-10-19 07:57:35 +02:00

93 lines
1.8 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\DB\QueryBuilder;
use OCP\DB\QueryBuilder\ICompositeExpression;
class CompositeExpression implements ICompositeExpression, \Countable {
public const TYPE_AND = 'AND';
public const TYPE_OR = 'OR';
public function __construct(
private string $type,
private array $parts = [],
) {
}
/**
* Adds multiple parts to composite expression.
*
* @param array $parts
*
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
public function addMultiple(array $parts = []): ICompositeExpression {
foreach ($parts as $part) {
$this->add($part);
}
return $this;
}
/**
* Adds an expression to composite expression.
*
* @param mixed $part
*
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
public function add($part): ICompositeExpression {
if ($part === null) {
return $this;
}
if ($part instanceof self && count($part) === 0) {
return $this;
}
$this->parts[] = $part;
return $this;
}
/**
* Retrieves the amount of expressions on composite expression.
*
* @return integer
*/
public function count(): int {
return count($this->parts);
}
/**
* Returns the type of this composite expression (AND/OR).
*
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* Retrieves the string representation of this composite expression.
*
* @return string
*/
public function __toString(): string {
if ($this->count() === 1) {
return (string)$this->parts[0];
}
return '(' . implode(') ' . $this->type . ' (', $this->parts) . ')';
}
public function getParts(): array {
return $this->parts;
}
}