Skip to content

Commit e8024a6

Browse files
Allow inverse application of the 'IN' operator
This commit adds a function to the ListType interface that allows for the inverse application of the 'IN' operator. More precisely, it allows you to call 'has' on a ListType to use the 'IN' operator. No new functionality is added.
1 parent f686e12 commit e8024a6

File tree

11 files changed

+125
-6
lines changed

11 files changed

+125
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wikibase-solutions/php-cypher-dsl",
33
"description": "A PHP DSL for the Cypher Query Language",
4-
"version": "2.5.0",
4+
"version": "2.6.0",
55
"type": "library",
66
"keywords": [
77
"neo4j",

src/ExpressionList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use TypeError;
2525
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
26+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2627
use WikibaseSolutions\CypherDSL\Types\AnyType;
2728
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\ListType;
2829

@@ -37,6 +38,7 @@
3738
class ExpressionList implements ListType
3839
{
3940
use EscapeTrait;
41+
use ListTypeTrait;
4042

4143
/**
4244
* @var array The list of expressions

src/Functions/RawFunction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use InvalidArgumentException;
2525
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
26+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2627
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Traits\NodeTypeTrait;
2829
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
@@ -50,6 +51,7 @@ class RawFunction extends FunctionCall implements
5051
PathType
5152
{
5253
use BooleanTypeTrait;
54+
use ListTypeTrait;
5355
use MapTypeTrait;
5456
use NodeTypeTrait;
5557
use NumeralTypeTrait;

src/Parameter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use InvalidArgumentException;
2525
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2626
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
27+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2829
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
2930
use WikibaseSolutions\CypherDSL\Traits\StringTypeTrait;
@@ -46,6 +47,7 @@ class Parameter implements
4647
StringType
4748
{
4849
use EscapeTrait;
50+
use ListTypeTrait;
4951
use BooleanTypeTrait;
5052
use MapTypeTrait;
5153
use NumeralTypeTrait;

src/Property.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2525
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
26+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2627
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
2829
use WikibaseSolutions\CypherDSL\Traits\StringTypeTrait;
@@ -40,6 +41,7 @@ class Property implements BooleanType, NumeralType, StringType, MapType, ListTyp
4041
{
4142
use EscapeTrait;
4243
use BooleanTypeTrait;
44+
use ListTypeTrait;
4345
use NumeralTypeTrait;
4446
use StringTypeTrait;
4547
use MapTypeTrait;

src/RawExpression.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace WikibaseSolutions\CypherDSL;
2323

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
25+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2526
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2627
use WikibaseSolutions\CypherDSL\Traits\NodeTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
@@ -49,6 +50,7 @@ class RawExpression implements
4950
PathType
5051
{
5152
use BooleanTypeTrait;
53+
use ListTypeTrait;
5254
use MapTypeTrait;
5355
use NodeTypeTrait;
5456
use NumeralTypeTrait;

src/Traits/ListTypeTrait.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Traits;
23+
24+
use WikibaseSolutions\CypherDSL\In;
25+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PropertyType;
26+
27+
/**
28+
* This trait should be used by any expression that returns a list.
29+
*/
30+
trait ListTypeTrait
31+
{
32+
/**
33+
* Checks whether the given element exists in this list.
34+
*
35+
* @param PropertyType $left
36+
* @return In
37+
*/
38+
public function has(PropertyType $left): In
39+
{
40+
return new In($left, $this);
41+
}
42+
}

src/Types/CompositeTypes/ListType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Types\CompositeTypes;
2323

24+
use WikibaseSolutions\CypherDSL\In;
25+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PropertyType;
26+
2427
/**
2528
* Represent the type "list".
2629
*/
2730
interface ListType extends CompositeType
2831
{
32+
/**
33+
* Checks whether the given element exists in this list.
34+
*
35+
* @param PropertyType $left
36+
* @return In
37+
*/
38+
public function has(PropertyType $left): In;
2939
}

src/Variable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use WikibaseSolutions\CypherDSL\Traits\AssignableTrait;
2525
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2626
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
27+
use WikibaseSolutions\CypherDSL\Traits\ListTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2829
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
2930
use WikibaseSolutions\CypherDSL\Traits\PathTypeTrait;
@@ -54,6 +55,7 @@ class Variable implements
5455
{
5556
use EscapeTrait;
5657
use BooleanTypeTrait;
58+
use ListTypeTrait;
5759
use MapTypeTrait;
5860
use NumeralTypeTrait;
5961
use PathTypeTrait;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Tests\Unit\Traits;
23+
24+
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\TestCase;
26+
use WikibaseSolutions\CypherDSL\In;
27+
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
28+
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\ListType;
29+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PropertyType;
30+
31+
/**
32+
* @covers \WikibaseSolutions\CypherDSL\Traits\ListTypeTrait
33+
*/
34+
class ListTypeTraitTest extends TestCase
35+
{
36+
use TestHelper;
37+
38+
/**
39+
* @var MockObject|PropertyType
40+
*/
41+
private $a;
42+
43+
/**
44+
* @var MockObject|ListType
45+
*/
46+
private $b;
47+
48+
public function setUp(): void
49+
{
50+
$this->a = $this->getQueryConvertableMock(PropertyType::class, "a");
51+
$this->b = $this->getQueryConvertableMock(ListType::class, "[]");
52+
}
53+
54+
public function testHas()
55+
{
56+
$has = $this->b->has($this->a);
57+
58+
$this->assertInstanceOf(In::class, $has);
59+
}
60+
}

0 commit comments

Comments
 (0)