Skip to content

Commit cb11867

Browse files
Minor fixes
1 parent b3aa7ad commit cb11867

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/Expressions/Literals/ExpressionList.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Expressions\Literals;
2323

24+
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
25+
use WikibaseSolutions\CypherDSL\Traits\CastTrait;
2426
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2527
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2628
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\CompositeTypeTraits\ListTypeTrait;
@@ -37,6 +39,7 @@
3739
*/
3840
final class ExpressionList implements ListType
3941
{
42+
use CastTrait;
4043
use EscapeTrait;
4144
use ErrorTrait;
4245
use ListTypeTrait;
@@ -51,12 +54,22 @@ final class ExpressionList implements ListType
5154
*
5255
* @param array $expressions The list of expressions
5356
*/
54-
public function __construct(iterable $expressions)
57+
public function __construct(array $expressions)
5558
{
56-
$this->expressions = array_map(
57-
fn ($value): AnyType => $value instanceof AnyType ? $value : Literal::literal($value),
58-
$expressions
59-
);
59+
$this->expressions = array_map([self::class, 'toAnyType'], $expressions);
60+
}
61+
62+
/**
63+
* Add one or more expressions to the list.
64+
*
65+
* @param AnyType|Pattern|int|float|string|bool|array ...$expressions
66+
* @return $this
67+
*/
68+
public function addExpression(...$expressions): self
69+
{
70+
$this->expressions = array_merge($this->expressions, array_map([self::class, 'toAnyType'], $expressions));
71+
72+
return $this;
6073
}
6174

6275
/**

src/Expressions/Literals/Map.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
*/
3838
final class Map implements MapType
3939
{
40-
use EscapeTrait;
41-
use ErrorTrait;
42-
use MapTypeTrait;
40+
use EscapeTrait;
41+
use ErrorTrait;
42+
use MapTypeTrait;
4343

4444
/**
4545
* @var AnyType[] The map of properties
@@ -53,7 +53,7 @@ final class Map implements MapType
5353
*/
5454
public function __construct(array $properties = [])
5555
{
56-
$this->properties = array_map(
56+
$this->properties = array_map(
5757
fn ($value): AnyType => $value instanceof AnyType ? $value : Literal::literal($value),
5858
$properties
5959
);

src/Expressions/Parameter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ final class Parameter implements
8787
/**
8888
* Parameter constructor.
8989
*
90-
* @param string|null $parameter The parameter; this parameter may only consist of alphanumeric
91-
* characters and underscores
90+
* @param string|null $parameter The parameter; this parameter may only consist of alphanumeric characters and
91+
* underscores
9292
*/
9393
public function __construct(?string $parameter = null)
9494
{
9595
if (!isset($parameter)) {
96-
$parameter = $this->generateString('param');
96+
$parameter = $this->generateIdentifier('param');
9797
} else {
98-
// Validation is only needed when the user supplied their own parameter
99-
self::assertValidName($parameter);
100-
}
98+
// Validation is only needed when the user supplied their own parameter
99+
self::assertValidName($parameter);
100+
}
101101

102102
$this->parameter = $parameter;
103103
}

0 commit comments

Comments
 (0)