Skip to content

Commit 406bf1e

Browse files
Merge pull request #38 from transistive/nullables
Add nullable comparison operators
2 parents abdf69c + f420c34 commit 406bf1e

14 files changed

+472
-0
lines changed

src/Alias.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL;
423

524
use function sprintf;

src/IsNotNull.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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;
23+
24+
use function sprintf;
25+
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
26+
use WikibaseSolutions\CypherDSL\Types\AnyType;
27+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
28+
29+
/**
30+
* Represents the IS NOT NULL comparison operator.
31+
*
32+
* @see https://neo4j.com/docs/cypher-manual/current/syntax/operators/#query-operators-comparison
33+
*/
34+
class IsNotNull implements BooleanType
35+
{
36+
use BooleanTypeTrait;
37+
38+
/**
39+
* @var AnyType The type to test against null
40+
*/
41+
private AnyType $expression;
42+
private bool $insertParentheses;
43+
44+
/**
45+
* IS NOT NULL constructor.
46+
*
47+
* @param AnyType $expression The type to test against null.
48+
*/
49+
public function __construct(AnyType $expression, bool $insertParentheses = true)
50+
{
51+
$this->expression = $expression;
52+
$this->insertParentheses = $insertParentheses;
53+
}
54+
55+
/**
56+
* Returns the expression to test against null.
57+
*
58+
* @return AnyType
59+
*/
60+
public function getExpression(): AnyType
61+
{
62+
return $this->expression;
63+
}
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
public function toQuery(): string
69+
{
70+
return sprintf($this->insertParentheses ? "(%s IS NOT NULL)" : "%s IS NOT NULL", $this->expression->toQuery());
71+
}
72+
73+
/**
74+
* Returns whether or not the operator inserts parenthesis.
75+
*
76+
* @return bool
77+
*/
78+
public function insertsParentheses(): bool
79+
{
80+
return $this->insertParentheses;
81+
}
82+
}

src/IsNull.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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;
23+
24+
use function sprintf;
25+
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
26+
use WikibaseSolutions\CypherDSL\Types\AnyType;
27+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
28+
29+
/**
30+
* Represents the IS NULL comparison operator.
31+
*
32+
* @see https://neo4j.com/docs/cypher-manual/current/syntax/operators/#query-operators-comparison
33+
*/
34+
class IsNull implements BooleanType
35+
{
36+
use BooleanTypeTrait;
37+
38+
/**
39+
* @var AnyType The type to test against null
40+
*/
41+
private AnyType $expression;
42+
private bool $insertParentheses;
43+
44+
/**
45+
* IS NULL constructor.
46+
*
47+
* @param AnyType $expression The type to test against null.
48+
*/
49+
public function __construct(AnyType $expression, bool $insertParentheses = true)
50+
{
51+
$this->expression = $expression;
52+
$this->insertParentheses = $insertParentheses;
53+
}
54+
55+
/**
56+
* Returns the expression to test against null.
57+
*
58+
* @return AnyType
59+
*/
60+
public function getExpression(): AnyType
61+
{
62+
return $this->expression;
63+
}
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
public function toQuery(): string
69+
{
70+
return sprintf($this->insertParentheses ? "(%s IS NULL)" : "%s IS NULL", $this->expression->toQuery());
71+
}
72+
73+
/**
74+
* Returns whether or not the operator inserts parenthesis.
75+
*
76+
* @return bool
77+
*/
78+
public function insertsParentheses(): bool
79+
{
80+
return $this->insertParentheses;
81+
}
82+
}

src/Patterns/Path.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Patterns;
423

524
use function array_key_exists;

src/Traits/AliasableTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Traits;
423

524
use function is_string;

src/Traits/HasNameTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Traits;
423

524
use function mt_rand;

src/Traits/HasPropertiesTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Traits;
423

524
use function is_array;

src/Traits/HasVariableTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Traits;
423

524
use function is_string;

src/Traits/PathTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

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+
322
namespace WikibaseSolutions\CypherDSL\Traits;
423

524
trait PathTrait

src/Traits/PropertyTypeTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use WikibaseSolutions\CypherDSL\Equality;
2525
use WikibaseSolutions\CypherDSL\In;
2626
use WikibaseSolutions\CypherDSL\Inequality;
27+
use WikibaseSolutions\CypherDSL\IsNotNull;
28+
use WikibaseSolutions\CypherDSL\IsNull;
2729
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\ListType;
2830
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PropertyType;
2931

@@ -70,4 +72,20 @@ public function in(ListType $right, bool $insertParentheses = true): In
7072
{
7173
return new In($this, $right, $insertParentheses);
7274
}
75+
76+
/**
77+
* @inheritDoc
78+
*/
79+
public function isNull(bool $insertParentheses = true): IsNull
80+
{
81+
return new IsNull($this, $insertParentheses);
82+
}
83+
84+
/**
85+
* @inheritDoc
86+
*/
87+
public function isNotNull(bool $insertParentheses = true): IsNotNull
88+
{
89+
return new IsNotNull($this, $insertParentheses);
90+
}
7391
}

0 commit comments

Comments
 (0)