Skip to content

Commit f420c34

Browse files
Merge branch 'main' into nullables
2 parents 3e06557 + abdf69c commit f420c34

20 files changed

+337
-202
lines changed

src/Equality.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
25+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
26+
use WikibaseSolutions\CypherDSL\Types\AnyType;
27+
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\CompositeType;
2528
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
2629
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PropertyType;
2730

@@ -34,12 +37,20 @@
3437
class Equality extends BinaryOperator implements BooleanType
3538
{
3639
use BooleanTypeTrait;
40+
use ErrorTrait;
3741

3842
/**
39-
* @inheritDoc
43+
* Equality constructor
44+
*
45+
* @param PropertyType|CompositeType $left The left-hand of the expression
46+
* @param PropertyType|CompositeType $right The right-hand of the expression
47+
* @param bool $insertParentheses Whether to insert parentheses around the expression
4048
*/
41-
public function __construct(PropertyType $left, PropertyType $right, bool $insertParentheses = true)
49+
public function __construct(Anytype $left, AnyType $right, bool $insertParentheses = true)
4250
{
51+
self::assertClass('left', [PropertyType::class, CompositeType::class], $left);
52+
self::assertClass('right', [PropertyType::class, CompositeType::class], $right);
53+
4354
parent::__construct($left, $right, $insertParentheses);
4455
}
4556

src/Exponentiation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
2626

2727
/**
28-
* Represents the application of the exponentiation (+) operator.
28+
* Represents the application of the exponentiation (^) operator.
2929
*
3030
* @see https://neo4j.com/docs/cypher-manual/current/syntax/operators/#syntax-using-the-exponentiation-operator
3131
*/

src/GreaterThan.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2525
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
26-
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType;
2727

2828
/**
2929
* Represents the application of the greater than (>) operator.
@@ -37,7 +37,7 @@ class GreaterThan extends BinaryOperator implements BooleanType
3737
/**
3838
* @inheritDoc
3939
*/
40-
public function __construct(NumeralType $left, NumeralType $right, bool $insertParentheses = true)
40+
public function __construct(ComparableType $left, ComparableType $right, bool $insertParentheses = true)
4141
{
4242
parent::__construct($left, $right, $insertParentheses);
4343
}

src/GreaterThanOrEqual.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2525
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
26-
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType;
2727

2828
/**
2929
* Represents the application of the greater than or equal to (>=) operator.
@@ -37,7 +37,7 @@ class GreaterThanOrEqual extends BinaryOperator implements BooleanType
3737
/**
3838
* @inheritDoc
3939
*/
40-
public function __construct(NumeralType $left, NumeralType $right, bool $insertParentheses = true)
40+
public function __construct(ComparableType $left, ComparableType $right, bool $insertParentheses = true)
4141
{
4242
parent::__construct($left, $right, $insertParentheses);
4343
}

src/LessThan.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2525
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
26-
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType;
2727

2828
/**
2929
* Represents the application of the less than (<) operator.
@@ -37,7 +37,7 @@ class LessThan extends BinaryOperator implements BooleanType
3737
/**
3838
* @inheritDoc
3939
*/
40-
public function __construct(NumeralType $left, NumeralType $right, bool $insertParentheses = true)
40+
public function __construct(ComparableType $left, ComparableType $right, bool $insertParentheses = true)
4141
{
4242
parent::__construct($left, $right, $insertParentheses);
4343
}

src/LessThanOrEqual.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
2525
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
26-
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType;
2727

2828
/**
2929
* Represents the application of the less than or equal to (<=) operator.
@@ -37,7 +37,7 @@ class LessThanOrEqual extends BinaryOperator implements BooleanType
3737
/**
3838
* @inheritDoc
3939
*/
40-
public function __construct(NumeralType $left, NumeralType $right, bool $insertParentheses = true)
40+
public function __construct(ComparableType $left, ComparableType $right, bool $insertParentheses = true)
4141
{
4242
parent::__construct($left, $right, $insertParentheses);
4343
}

src/Traits/ComparableTypeTrait.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\GreaterThan;
25+
use WikibaseSolutions\CypherDSL\GreaterThanOrEqual;
26+
use WikibaseSolutions\CypherDSL\LessThan;
27+
use WikibaseSolutions\CypherDSL\LessThanOrEqual;
28+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\ComparableType;
29+
30+
/**
31+
* This trait should be used by any expression that returns a numeral.
32+
*/
33+
trait ComparableTypeTrait
34+
{
35+
use PropertyTypeTrait;
36+
37+
/**
38+
* Perform a greater than comparison against the given expression.
39+
*
40+
* @param ComparableType $right
41+
* @param bool $insertParentheses
42+
* @return GreaterThan
43+
*/
44+
public function gt(ComparableType $right, bool $insertParentheses = true): GreaterThan
45+
{
46+
return new GreaterThan($this, $right, $insertParentheses);
47+
}
48+
49+
/**
50+
* Perform a greater than or equal comparison against the given expression.
51+
*
52+
* @param ComparableType $right
53+
* @param bool $insertParentheses
54+
* @return GreaterThanOrEqual
55+
*/
56+
public function gte(ComparableType $right, bool $insertParentheses = true): GreaterThanOrEqual
57+
{
58+
return new GreaterThanOrEqual($this, $right, $insertParentheses);
59+
}
60+
61+
/**
62+
* Perform a less than comparison against the given expression.
63+
*
64+
* @param ComparableType $right
65+
* @param bool $insertParentheses
66+
* @return LessThan
67+
*/
68+
public function lt(ComparableType $right, bool $insertParentheses = true): LessThan
69+
{
70+
return new LessThan($this, $right, $insertParentheses);
71+
}
72+
73+
/**
74+
* Perform a less than or equal comparison against the given expression.
75+
*
76+
* @param ComparableType $right
77+
* @param bool $insertParentheses
78+
* @return LessThanOrEqual
79+
*/
80+
public function lte(ComparableType $right, bool $insertParentheses = true): LessThanOrEqual
81+
{
82+
return new LessThanOrEqual($this, $right, $insertParentheses);
83+
}
84+
}

src/Traits/DateTimeTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
trait DateTimeTrait
2828
{
2929
use PropertyTypeTrait;
30+
use ComparableTypeTrait;
3031
}

src/Traits/DateTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
trait DateTrait
2828
{
2929
use PropertyTypeTrait;
30+
use ComparableTypeTrait;
3031
}

src/Traits/NumeralTypeTrait.php

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
use WikibaseSolutions\CypherDSL\Addition;
2525
use WikibaseSolutions\CypherDSL\Division;
2626
use WikibaseSolutions\CypherDSL\Exponentiation;
27-
use WikibaseSolutions\CypherDSL\GreaterThan;
28-
use WikibaseSolutions\CypherDSL\GreaterThanOrEqual;
29-
use WikibaseSolutions\CypherDSL\LessThan;
30-
use WikibaseSolutions\CypherDSL\LessThanOrEqual;
3127
use WikibaseSolutions\CypherDSL\Minus;
3228
use WikibaseSolutions\CypherDSL\Modulo;
3329
use WikibaseSolutions\CypherDSL\Multiplication;
@@ -39,8 +35,9 @@
3935
*/
4036
trait NumeralTypeTrait
4137
{
42-
use PropertyTypeTrait;
4338
use AliasableTrait;
39+
use ComparableTypeTrait;
40+
use PropertyTypeTrait;
4441

4542
/**
4643
* Add this expression to the given expression.
@@ -78,54 +75,6 @@ public function exponentiate(NumeralType $right, bool $insertParentheses = true)
7875
return new Exponentiation($this, $right, $insertParentheses);
7976
}
8077

81-
/**
82-
* Perform a greater than comparison against the given expression.
83-
*
84-
* @param NumeralType $right
85-
* @param bool $insertParentheses
86-
* @return GreaterThan
87-
*/
88-
public function gt(NumeralType $right, bool $insertParentheses = true): GreaterThan
89-
{
90-
return new GreaterThan($this, $right, $insertParentheses);
91-
}
92-
93-
/**
94-
* Perform a greater than or equal comparison against the given expression.
95-
*
96-
* @param NumeralType $right
97-
* @param bool $insertParentheses
98-
* @return GreaterThanOrEqual
99-
*/
100-
public function gte(NumeralType $right, bool $insertParentheses = true): GreaterThanOrEqual
101-
{
102-
return new GreaterThanOrEqual($this, $right, $insertParentheses);
103-
}
104-
105-
/**
106-
* Perform a less than comparison against the given expression.
107-
*
108-
* @param NumeralType $right
109-
* @param bool $insertParentheses
110-
* @return LessThan
111-
*/
112-
public function lt(NumeralType $right, bool $insertParentheses = true): LessThan
113-
{
114-
return new LessThan($this, $right, $insertParentheses);
115-
}
116-
117-
/**
118-
* Perform a less than or equal comparison against the given expression.
119-
*
120-
* @param NumeralType $right
121-
* @param bool $insertParentheses
122-
* @return LessThanOrEqual
123-
*/
124-
public function lte(NumeralType $right, bool $insertParentheses = true): LessThanOrEqual
125-
{
126-
return new LessThanOrEqual($this, $right, $insertParentheses);
127-
}
128-
12978
/**
13079
* Perform the modulo operation with the given expression.
13180
*

0 commit comments

Comments
 (0)