Fix coding style with phpcs PSR-12 standard
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
b77ffd7f38
commit
39ae737fa1
30 changed files with 264 additions and 205 deletions
|
|
@ -36,3 +36,10 @@ echo $queryBuilder->build();
|
||||||
```
|
```
|
||||||
php vendor/bin/phpunit --testdox
|
php vendor/bin/phpunit --testdox
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Coding style
|
||||||
|
|
||||||
|
```
|
||||||
|
./vendor/bin/phpcbf --standard=PSR12 ./src
|
||||||
|
./vendor/bin/phpcbf --standard=PSR12 ./tests
|
||||||
|
```
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
"php": ">=7.2"
|
"php": ">=7.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^8"
|
"phpunit/phpunit": "^8",
|
||||||
|
"squizlabs/php_codesniffer": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
58
composer.lock
generated
58
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "dd145ce324fb9a1982c8f4fe8741808b",
|
"content-hash": "91e60dd99295cc037b7dcefac530fa16",
|
||||||
"packages": [],
|
"packages": [],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
|
|
@ -1594,6 +1594,62 @@
|
||||||
},
|
},
|
||||||
"time": "2016-10-03T07:35:21+00:00"
|
"time": "2016-10-03T07:35:21+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "squizlabs/php_codesniffer",
|
||||||
|
"version": "3.7.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
|
||||||
|
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
|
||||||
|
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-simplexml": "*",
|
||||||
|
"ext-tokenizer": "*",
|
||||||
|
"ext-xmlwriter": "*",
|
||||||
|
"php": ">=5.4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"bin/phpcs",
|
||||||
|
"bin/phpcbf"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Greg Sherwood",
|
||||||
|
"role": "lead"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
|
||||||
|
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
|
||||||
|
"keywords": [
|
||||||
|
"phpcs",
|
||||||
|
"standards"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
|
||||||
|
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
|
||||||
|
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
|
||||||
|
},
|
||||||
|
"time": "2022-06-18T07:21:10+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "theseer/tokenizer",
|
"name": "theseer/tokenizer",
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,6 @@ namespace Arendsen\FluxQueryBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class ExpressionNotImplementedException extends Exception {}
|
class ExpressionNotImplementedException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,6 @@ namespace Arendsen\FluxQueryBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class FunctionNotImplementedException extends Exception {}
|
class FunctionNotImplementedException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@ namespace Arendsen\FluxQueryBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class FunctionRequiredSettingMissingException extends Exception {
|
class FunctionRequiredSettingMissingException extends Exception
|
||||||
|
{
|
||||||
public function __construct(string $functionName, string $message)
|
public function __construct(string $functionName, string $message)
|
||||||
{
|
{
|
||||||
parent::__construct('Function ' . $functionName . ' - ' . $message);
|
parent::__construct('Function ' . $functionName . ' - ' . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
|
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
|
||||||
|
|
||||||
abstract class Base {
|
abstract class Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @throws ExpressionNotImplementedException
|
* @throws ExpressionNotImplementedException
|
||||||
*/
|
*/
|
||||||
|
|
@ -13,5 +13,4 @@ abstract class Base {
|
||||||
{
|
{
|
||||||
throw new ExpressionNotImplementedException('__toString', get_class($this));
|
throw new ExpressionNotImplementedException('__toString', get_class($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,18 +5,18 @@ namespace Arendsen\FluxQueryBuilder\Expression;
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class KeyValue extends Base {
|
class KeyValue extends Base
|
||||||
|
{
|
||||||
|
public const EQUAL_TO = '==';
|
||||||
|
public const NOT_EQUAL_TO = '!=';
|
||||||
|
public const GREATER_THAN = '>';
|
||||||
|
public const GREATER_EQUAL_TO = '>=';
|
||||||
|
public const LESS_THAN = '<';
|
||||||
|
public const LESS_EQUAL_TO = '<=';
|
||||||
|
public const EQUAL_TO_REGEX = '=~';
|
||||||
|
public const NOT_EQUAL_TO_REGEX = '!~';
|
||||||
|
|
||||||
const EQUAL_TO = '==';
|
public const COMPARISON_OPERATORS = [
|
||||||
const NOT_EQUAL_TO = '!=';
|
|
||||||
const GREATER_THAN = '>';
|
|
||||||
const GREATER_EQUAL_TO = '>=';
|
|
||||||
const LESS_THAN = '<';
|
|
||||||
const LESS_EQUAL_TO = '<=';
|
|
||||||
const EQUAL_TO_REGEX = '=~';
|
|
||||||
const NOT_EQUAL_TO_REGEX = '!~';
|
|
||||||
|
|
||||||
const COMPARISON_OPERATORS = [
|
|
||||||
self::EQUAL_TO,
|
self::EQUAL_TO,
|
||||||
self::NOT_EQUAL_TO,
|
self::NOT_EQUAL_TO,
|
||||||
self::GREATER_THAN,
|
self::GREATER_THAN,
|
||||||
|
|
@ -200,10 +200,8 @@ class KeyValue extends Base {
|
||||||
|
|
||||||
protected function checkOperator(string $operator)
|
protected function checkOperator(string $operator)
|
||||||
{
|
{
|
||||||
if(!in_array($operator, self::COMPARISON_OPERATORS))
|
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
|
||||||
{
|
|
||||||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
throw new Exception('Operator "' . $operator . '" is not supported!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,20 +4,15 @@ namespace Arendsen\FluxQueryBuilder;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Formatters {
|
class Formatters
|
||||||
|
{
|
||||||
public static function valueToString($value): string
|
public static function valueToString($value): string
|
||||||
{
|
{
|
||||||
if(is_string($value))
|
if (is_string($value)) {
|
||||||
{
|
|
||||||
return '"' . $value . '"';
|
return '"' . $value . '"';
|
||||||
}
|
} elseif (is_bool($value)) {
|
||||||
elseif(is_bool($value))
|
|
||||||
{
|
|
||||||
return $value ? 'true' : 'false';
|
return $value ? 'true' : 'false';
|
||||||
}
|
} elseif (is_array($value)) {
|
||||||
elseif(is_array($value))
|
|
||||||
{
|
|
||||||
return '[' . self::toFluxArrayString($value) . ']';
|
return '[' . self::toFluxArrayString($value) . ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,13 +21,10 @@ class Formatters {
|
||||||
|
|
||||||
public static function toFluxArrayString(array $array): string
|
public static function toFluxArrayString(array $array): string
|
||||||
{
|
{
|
||||||
array_walk($array, function(&$value, $key) {
|
array_walk($array, function (&$value, $key) {
|
||||||
if(is_string($key))
|
if (is_string($key)) {
|
||||||
{
|
|
||||||
$value = $key . ': ' . self::valueToString($value);
|
$value = $key . ': ' . self::valueToString($value);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$value = self::valueToString($value);
|
$value = self::valueToString($value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -40,8 +32,8 @@ class Formatters {
|
||||||
return implode(', ', $array);
|
return implode(', ', $array);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dateTimeToString(DateTime $dateTime): string {
|
public static function dateTimeToString(DateTime $dateTime): string
|
||||||
|
{
|
||||||
return 'time(v: ' . $dateTime->format('Y-m-d\TH:i:s\Z') . ')';
|
return 'time(v: ' . $dateTime->format('Y-m-d\TH:i:s\Z') . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,8 +5,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
use Arendsen\FluxQueryBuilder\Exception\FunctionNotImplementedException;
|
use Arendsen\FluxQueryBuilder\Exception\FunctionNotImplementedException;
|
||||||
|
|
||||||
abstract class Base {
|
abstract class Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @throws FunctionNotImplementedException
|
* @throws FunctionNotImplementedException
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,5 +14,4 @@ abstract class Base {
|
||||||
{
|
{
|
||||||
throw new FunctionNotImplementedException('__toString', get_class($this));
|
throw new FunctionNotImplementedException('__toString', get_class($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||||
|
|
||||||
class Filter extends Base {
|
class Filter extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var KeyValue $keyValue
|
* @var KeyValue $keyValue
|
||||||
*/
|
*/
|
||||||
|
|
@ -20,5 +20,4 @@ class Filter extends Base {
|
||||||
{
|
{
|
||||||
return '|> filter(fn: (r) => ' . $this->keyValue . ') ';
|
return '|> filter(fn: (r) => ' . $this->keyValue . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
|
|
||||||
class From extends Base {
|
class From extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $settings
|
* @var array $settings
|
||||||
*/
|
*/
|
||||||
|
|
@ -20,5 +20,4 @@ class From extends Base {
|
||||||
{
|
{
|
||||||
return 'from(' . Formatters::toFluxArrayString($this->settings) . ') ';
|
return 'from(' . Formatters::toFluxArrayString($this->settings) . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
|
|
||||||
class Group extends Base {
|
class Group extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $columns
|
* @var array $columns
|
||||||
*/
|
*/
|
||||||
|
|
@ -31,5 +31,4 @@ class Group extends Base {
|
||||||
|
|
||||||
return '|> group(' . $array . ') ';
|
return '|> group(' . $array . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
class Limit extends Base {
|
class Limit extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var int $limit
|
* @var int $limit
|
||||||
*/
|
*/
|
||||||
|
|
@ -18,5 +18,4 @@ class Limit extends Base {
|
||||||
{
|
{
|
||||||
return '|> limit(n:' . (string)$this->limit . ') ';
|
return '|> limit(n:' . (string)$this->limit . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
class Map extends Base {
|
class Map extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $query
|
* @var array $query
|
||||||
*/
|
*/
|
||||||
|
|
@ -18,5 +18,4 @@ class Map extends Base {
|
||||||
{
|
{
|
||||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,8 @@ use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Range extends Base {
|
class Range extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var mixed $start
|
* @var mixed $start
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,18 +26,15 @@ class Range extends Base {
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
if(!$this->start)
|
if (!$this->start) {
|
||||||
{
|
|
||||||
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
|
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingsString = 'start: ' . $this->start;
|
$settingsString = 'start: ' . $this->start;
|
||||||
if($this->stop)
|
if ($this->stop) {
|
||||||
{
|
|
||||||
$settingsString .= ', stop: ' . $this->stop;
|
$settingsString .= ', stop: ' . $this->stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '|> range(' . $settingsString . ') ';
|
return '|> range(' . $settingsString . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
|
|
||||||
class Reduce extends Base {
|
class Reduce extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $settings
|
* @var array $settings
|
||||||
*/
|
*/
|
||||||
|
|
@ -30,11 +30,10 @@ class Reduce extends Base {
|
||||||
|
|
||||||
protected function formatSettings(array $settings)
|
protected function formatSettings(array $settings)
|
||||||
{
|
{
|
||||||
array_walk($settings, function(&$value, $key) {
|
array_walk($settings, function (&$value, $key) {
|
||||||
$value = $key . ': ' . $value;
|
$value = $key . ': ' . $value;
|
||||||
});
|
});
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
|
|
||||||
class Sort extends Base {
|
class Sort extends Base
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $columns
|
* @var array $columns
|
||||||
*/
|
*/
|
||||||
|
|
@ -27,5 +27,4 @@ class Sort extends Base {
|
||||||
return '|> sort(columns: [' . Formatters::toFluxArrayString($this->columns) .
|
return '|> sort(columns: [' . Formatters::toFluxArrayString($this->columns) .
|
||||||
'], desc: ' . Formatters::valueToString($this->desc) . ') ';
|
'], desc: ' . Formatters::valueToString($this->desc) . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -14,18 +14,18 @@ use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
use Arendsen\FluxQueryBuilder\Functions\Group;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
||||||
|
|
||||||
class QueryBuilder {
|
class QueryBuilder
|
||||||
|
{
|
||||||
|
public const FLUX_PART_FROM = 'from';
|
||||||
|
public const FLUX_PART_RANGE = 'range';
|
||||||
|
public const FLUX_PART_FILTERS = 'filters';
|
||||||
|
public const FLUX_PART_REDUCE = 'reduce';
|
||||||
|
public const FLUX_PART_MAP = 'map';
|
||||||
|
public const FLUX_PART_SORT = 'sort';
|
||||||
|
public const FLUX_PART_GROUP = 'group';
|
||||||
|
public const FLUX_PART_LIMIT = 'limit';
|
||||||
|
|
||||||
const FLUX_PART_FROM = 'from';
|
public const PARTS = [
|
||||||
const FLUX_PART_RANGE = 'range';
|
|
||||||
const FLUX_PART_FILTERS = 'filters';
|
|
||||||
const FLUX_PART_REDUCE = 'reduce';
|
|
||||||
const FLUX_PART_MAP = 'map';
|
|
||||||
const FLUX_PART_SORT = 'sort';
|
|
||||||
const FLUX_PART_GROUP = 'group';
|
|
||||||
const FLUX_PART_LIMIT = 'limit';
|
|
||||||
|
|
||||||
const PARTS = [
|
|
||||||
self::FLUX_PART_FROM,
|
self::FLUX_PART_FROM,
|
||||||
self::FLUX_PART_RANGE,
|
self::FLUX_PART_RANGE,
|
||||||
self::FLUX_PART_REDUCE,
|
self::FLUX_PART_REDUCE,
|
||||||
|
|
@ -36,11 +36,11 @@ class QueryBuilder {
|
||||||
self::FLUX_PART_LIMIT,
|
self::FLUX_PART_LIMIT,
|
||||||
];
|
];
|
||||||
|
|
||||||
const REQUIRED_INPUT_FROM = 'from';
|
public const REQUIRED_INPUT_FROM = 'from';
|
||||||
const REQUIRED_INPUT_MEASUREMENT = 'measurement';
|
public const REQUIRED_INPUT_MEASUREMENT = 'measurement';
|
||||||
const REQUIRED_INPUT_RANGE = 'range';
|
public const REQUIRED_INPUT_RANGE = 'range';
|
||||||
|
|
||||||
const REQUIRED_INPUT = [
|
public const REQUIRED_INPUT = [
|
||||||
self::REQUIRED_INPUT_FROM,
|
self::REQUIRED_INPUT_FROM,
|
||||||
self::REQUIRED_INPUT_MEASUREMENT,
|
self::REQUIRED_INPUT_MEASUREMENT,
|
||||||
self::REQUIRED_INPUT_RANGE,
|
self::REQUIRED_INPUT_RANGE,
|
||||||
|
|
@ -174,18 +174,13 @@ class QueryBuilder {
|
||||||
|
|
||||||
$query = '';
|
$query = '';
|
||||||
|
|
||||||
foreach(self::PARTS as $part)
|
foreach (self::PARTS as $part) {
|
||||||
{
|
if (isset($this->fluxQueryParts[$part])) {
|
||||||
if(isset($this->fluxQueryParts[$part]))
|
if (is_array($this->fluxQueryParts[$part])) {
|
||||||
{
|
foreach ($this->fluxQueryParts[$part] as $filter) {
|
||||||
if(is_array($this->fluxQueryParts[$part]))
|
|
||||||
{
|
|
||||||
foreach($this->fluxQueryParts[$part] as $filter) {
|
|
||||||
$query .= $filter;
|
$query .= $filter;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$query .= $this->fluxQueryParts[$part];
|
$query .= $this->fluxQueryParts[$part];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -194,18 +189,17 @@ class QueryBuilder {
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addRequiredData(string $key, $value) {
|
protected function addRequiredData(string $key, $value)
|
||||||
|
{
|
||||||
$this->requiredData[$key] = $value;
|
$this->requiredData[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkRequired()
|
protected function checkRequired()
|
||||||
{
|
{
|
||||||
foreach(self::REQUIRED_INPUT as $input) {
|
foreach (self::REQUIRED_INPUT as $input) {
|
||||||
if(!isset($this->requiredData[$input]))
|
if (!isset($this->requiredData[$input])) {
|
||||||
{
|
|
||||||
throw new Exception('You need to define the "' . $input . '" part of the query!');
|
throw new Exception('You need to define the "' . $input . '" part of the query!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class KeyValueExpressionTest extends TestCase {
|
final class KeyValueExpressionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleKeyvalue()
|
public function testSimpleKeyvalue()
|
||||||
{
|
{
|
||||||
$keyvalue = KeyValue::setEqualTo('_measurement', 'test_measurement')
|
$keyvalue = KeyValue::setEqualTo('_measurement', 'test_measurement')
|
||||||
|
|
@ -29,5 +32,4 @@ final class KeyValueExpressionTest extends TestCase {
|
||||||
->or('_field', '==', 'field2')
|
->or('_field', '==', 'field2')
|
||||||
->andEqualTo('user', 'my_username');
|
->andEqualTo('user', 'my_username');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,24 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FilterFunctionTest extends TestCase {
|
final class FilterFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleFilter()
|
public function testSimpleFilter()
|
||||||
{
|
{
|
||||||
$expression = new Filter(KeyValue::setEqualTo('_measurement', 'test_measurement')
|
$expression = new Filter(KeyValue::setEqualTo('_measurement', 'test_measurement')
|
||||||
->andEqualTo('_field', 'user')
|
->andEqualTo('_field', 'user')
|
||||||
->orEqualTo('_field', 'field2')
|
->orEqualTo('_field', 'field2')
|
||||||
->andEqualTo('user', 'my_username')
|
->andEqualTo('user', 'my_username'));
|
||||||
);
|
|
||||||
|
|
||||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||||
'r._field == "field2" and r.user == "my_username") ';
|
'r._field == "field2" and r.user == "my_username") ';
|
||||||
|
|
||||||
$this->assertEquals($expression->__toString(), $query);
|
$this->assertEquals($expression->__toString(), $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
use Arendsen\FluxQueryBuilder\Functions\From;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FromFunctionTest extends TestCase {
|
final class FromFunctionTest extends TestCase
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider somethingProvider
|
* @dataProvider somethingProvider
|
||||||
*/
|
*/
|
||||||
|
|
@ -34,5 +37,4 @@ final class FromFunctionTest extends TestCase {
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
use Arendsen\FluxQueryBuilder\Functions\Group;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class GroupFunctionTest extends TestCase {
|
final class GroupFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleGroup()
|
public function testSimpleGroup()
|
||||||
{
|
{
|
||||||
$expression = new Group(['foo', 'bar'], 'by');
|
$expression = new Group(['foo', 'bar'], 'by');
|
||||||
|
|
@ -14,5 +17,4 @@ final class GroupFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class LimitFunctionTest extends TestCase {
|
final class LimitFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleLimit()
|
public function testSimpleLimit()
|
||||||
{
|
{
|
||||||
$expression = new Limit(1);
|
$expression = new Limit(1);
|
||||||
|
|
@ -14,5 +17,4 @@ final class LimitFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class MapFunctionTest extends TestCase {
|
final class MapFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleMap()
|
public function testSimpleMap()
|
||||||
{
|
{
|
||||||
$expression = new Map('r with name: r.user');
|
$expression = new Map('r with name: r.user');
|
||||||
|
|
@ -14,5 +17,4 @@ final class MapFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
|
namespace Tests\Functions;
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
|
||||||
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
use Arendsen\FluxQueryBuilder\Functions\Range;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class RangeFunctionTest extends TestCase {
|
final class RangeFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testOnlyStartOption()
|
public function testOnlyStartOption()
|
||||||
{
|
{
|
||||||
$expression = new Range(
|
$expression = new Range(
|
||||||
|
|
@ -42,5 +44,4 @@ final class RangeFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expected, $expression->__toString());
|
$this->assertEquals($expected, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class ReduceFunctionTest extends TestCase {
|
final class ReduceFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleReduce()
|
public function testSimpleReduce()
|
||||||
{
|
{
|
||||||
$expression = new Reduce(['sum' => 'r._value + accumulator.sum'], ['sum' => 0]);
|
$expression = new Reduce(['sum' => 'r._value + accumulator.sum'], ['sum' => 0]);
|
||||||
|
|
@ -14,5 +17,4 @@ final class ReduceFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class SortFunctionTest extends TestCase {
|
final class SortFunctionTest extends TestCase
|
||||||
|
{
|
||||||
public function testSimpleSort()
|
public function testSimpleSort()
|
||||||
{
|
{
|
||||||
$expression = new Sort(['foo', 'bar'], true);
|
$expression = new Sort(['foo', 'bar'], true);
|
||||||
|
|
@ -14,5 +17,4 @@ final class SortFunctionTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Generic;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\Formatters;
|
use Arendsen\FluxQueryBuilder\Formatters;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FormattersTest extends TestCase {
|
final class FormattersTest extends TestCase
|
||||||
|
{
|
||||||
public function testAssociativeArrayNested()
|
public function testAssociativeArrayNested()
|
||||||
{
|
{
|
||||||
$array = [
|
$array = [
|
||||||
|
|
@ -26,5 +30,4 @@ final class FormattersTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expected, Formatters::dateTimeToString($dateTime));
|
$this->assertEquals($expected, Formatters::dateTimeToString($dateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Generic;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
||||||
|
|
||||||
final class QueryBuilderTest extends TestCase {
|
final class QueryBuilderTest extends TestCase
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider simpleQueryProvider
|
* @dataProvider simpleQueryProvider
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,8 +20,7 @@ final class QueryBuilderTest extends TestCase {
|
||||||
->fromMeasurement($measurement)
|
->fromMeasurement($measurement)
|
||||||
->addRangeStart($range);
|
->addRangeStart($range);
|
||||||
|
|
||||||
if($keyValue)
|
if ($keyValue) {
|
||||||
{
|
|
||||||
$queryBuilder->addFilter($keyValue);
|
$queryBuilder->addFilter($keyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,13 +63,13 @@ final class QueryBuilderTest extends TestCase {
|
||||||
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
|
|
||||||
if($from) {
|
if ($from) {
|
||||||
$queryBuilder->from($from);
|
$queryBuilder->from($from);
|
||||||
}
|
}
|
||||||
if($measurement) {
|
if ($measurement) {
|
||||||
$queryBuilder->fromMeasurement($measurement);
|
$queryBuilder->fromMeasurement($measurement);
|
||||||
}
|
}
|
||||||
if($range) {
|
if ($range) {
|
||||||
$queryBuilder->addRangeStart($range['start']);
|
$queryBuilder->addRangeStart($range['start']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,5 +111,4 @@ final class QueryBuilderTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue