Skip to content

Commit 986f327

Browse files
author
Wout Gevaert
committed
Make a ComparableType for comparison of dates.
Fixes issue 49
1 parent ab36737 commit 986f327

14 files changed

+169
-105
lines changed

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: 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\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+
/**
36+
* Perform a greater than comparison against the given expression.
37+
*
38+
* @param ComparableType $right
39+
* @param bool $insertParentheses
40+
* @return GreaterThan
41+
*/
42+
public function gt(ComparableType $right, bool $insertParentheses = true): GreaterThan
43+
{
44+
return new GreaterThan($this, $right, $insertParentheses);
45+
}
46+
47+
/**
48+
* Perform a greater than or equal comparison against the given expression.
49+
*
50+
* @param ComparableType $right
51+
* @param bool $insertParentheses
52+
* @return GreaterThanOrEqual
53+
*/
54+
public function gte(ComparableType $right, bool $insertParentheses = true): GreaterThanOrEqual
55+
{
56+
return new GreaterThanOrEqual($this, $right, $insertParentheses);
57+
}
58+
59+
/**
60+
* Perform a less than comparison against the given expression.
61+
*
62+
* @param ComparableType $right
63+
* @param bool $insertParentheses
64+
* @return LessThan
65+
*/
66+
public function lt(ComparableType $right, bool $insertParentheses = true): LessThan
67+
{
68+
return new LessThan($this, $right, $insertParentheses);
69+
}
70+
71+
/**
72+
* Perform a less than or equal comparison against the given expression.
73+
*
74+
* @param ComparableType $right
75+
* @param bool $insertParentheses
76+
* @return LessThanOrEqual
77+
*/
78+
public function lte(ComparableType $right, bool $insertParentheses = true): LessThanOrEqual
79+
{
80+
return new LessThanOrEqual($this, $right, $insertParentheses);
81+
}
82+
}

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
*

src/Traits/TimeTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
trait TimeTrait
2828
{
2929
use PropertyTypeTrait;
30+
use ComparableTypeTrait;
3031
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\Types\PropertyTypes;
23+
24+
use WikibaseSolutions\CypherDSL\Addition;
25+
use WikibaseSolutions\CypherDSL\GreaterThan;
26+
use WikibaseSolutions\CypherDSL\GreaterThanOrEqual;
27+
use WikibaseSolutions\CypherDSL\LessThan;
28+
use WikibaseSolutions\CypherDSL\LessThanOrEqual;
29+
30+
/**
31+
* Represents any type that can be compared with operators such as <=, >=, < and >.
32+
*/
33+
interface ComparableType extends PropertyType
34+
{
35+
/**
36+
* Perform a greater than comparison against the given expression.
37+
*
38+
* @param NumeralType $right
39+
* @param bool $insertParentheses
40+
* @return GreaterThan
41+
*/
42+
public function gt(ComparableType $right, bool $insertParentheses = true): GreaterThan;
43+
44+
/**
45+
* Perform a greater than or equal comparison against the given expression.
46+
*
47+
* @param NumeralType $right
48+
* @param bool $insertParentheses
49+
* @return GreaterThanOrEqual
50+
*/
51+
public function gte(ComparableType $right, bool $insertParentheses = true): GreaterThanOrEqual;
52+
53+
/**
54+
* Perform a less than comparison against the given expression.
55+
*
56+
* @param NumeralType $right
57+
* @param bool $insertParentheses
58+
* @return LessThan
59+
*/
60+
public function lt(ComparableType $right, bool $insertParentheses = true): LessThan;
61+
62+
/**
63+
* Perform a less than or equal comparison against the given expression.
64+
*
65+
* @param NumeralType $right
66+
* @param bool $insertParentheses
67+
* @return LessThanOrEqual
68+
*/
69+
public function lte(ComparableType $right, bool $insertParentheses = true): LessThanOrEqual;
70+
}

0 commit comments

Comments
 (0)