Make FnType accept params and content

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-09-09 11:07:42 +00:00
commit 1bc585b2c8
3 changed files with 27 additions and 3 deletions

View file

@ -1,7 +1,7 @@
# InfluxDB 2.x Flux Query Builder # InfluxDB 2.x Flux Query Builder
With this query builder you can build queries for Flux. With this query builder you can build queries for Flux.
See https://docs.influxdata.com/influxdb/v2.3/query-data/flux/ See https://docs.influxdata.com/influxdb/v2.4/query-data/flux/
## Installation ## Installation

View file

@ -4,13 +4,28 @@ namespace Arendsen\FluxQueryBuilder\Type;
class FnType implements TypeInterface class FnType implements TypeInterface
{ {
public function __construct(string $value) /**
* @var mixed $value
*/
protected $value;
/**
* @var string $content
*/
protected $content;
public function __construct($value, string $content = '')
{ {
$this->value = $value; $this->value = $value;
$this->content = $content;
} }
public function __toString(): string public function __toString(): string
{ {
if(is_string($this->value)) {
return $this->value; return $this->value;
} }
return '(' . implode(', ', $this->value) . ') => ' . $this->content;
}
} }

View file

@ -8,6 +8,7 @@ use DateTime;
use Arendsen\FluxQueryBuilder\Type; use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\CustomType; use Arendsen\FluxQueryBuilder\Type\CustomType;
use Arendsen\FluxQueryBuilder\Type\DurationType; use Arendsen\FluxQueryBuilder\Type\DurationType;
use Arendsen\FluxQueryBuilder\Type\FnType;
use Arendsen\FluxQueryBuilder\Type\MathType; use Arendsen\FluxQueryBuilder\Type\MathType;
use Arendsen\FluxQueryBuilder\Type\RecordType; use Arendsen\FluxQueryBuilder\Type\RecordType;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -79,6 +80,14 @@ final class FactoryTypeTest extends TestCase
new CustomType('this can be anything'), new CustomType('this can be anything'),
'this can be anything' 'this can be anything'
], ],
'FnType with only content' => [
new FnType('(r) => ({ r with _value: r._value * r._value })'),
'(r) => ({ r with _value: r._value * r._value })'
],
'FnType with params and content' => [
new FnType(['r', 'a'], '({ r with _value: r._value * r._value })'),
'(r, a) => ({ r with _value: r._value * r._value })'
],
]; ];
} }
} }