Skip to content

Commit 453b4bd

Browse files
Split NumeralType into FloatType and IntegerType, other fixes
1 parent 875d4ce commit 453b4bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+937
-1273
lines changed

src/Clauses/MatchClause.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24+
use WikibaseSolutions\CypherDSL\Patterns\MatchablePattern;
2425
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2526
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
2627
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
@@ -42,30 +43,26 @@ class MatchClause extends Clause
4243
/**
4344
* Sets the pattern of the MATCH clause. This overwrites any previously added patterns.
4445
*
45-
* @param PathType[]|NodeType[] $patterns
46+
* @param MatchablePattern[] $patterns
4647
* @return $this
4748
*/
4849
public function setPatterns(array $patterns): self
4950
{
50-
foreach ($patterns as $pattern) {
51-
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
52-
}
53-
51+
self::assertClassArray('patterns', MatchablePattern::class, $patterns);
5452
$this->patterns = $patterns;
5553

5654
return $this;
5755
}
5856

5957
/**
60-
* Add a pattern to the MATCH clause.
58+
* Add one or more patterns to the MATCH clause.
6159
*
62-
* @param PathType|NodeType $pattern
60+
* @param MatchablePattern ...$pattern
6361
* @return MatchClause
6462
*/
65-
public function addPattern($pattern): self
63+
public function addPattern(MatchablePattern ...$pattern): self
6664
{
67-
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
68-
$this->patterns[] = $pattern;
65+
$this->patterns = array_merge($this->patterns, $pattern);
6966

7067
return $this;
7168
}

src/Expressions/Exists.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
<?php
2-
1+
<?php declare(strict_types=1);
32
/*
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.
3+
* This file is part of php-cypher-dsl.
114
*
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.
5+
* Copyright (C) 2021 Wikibase Solutions
166
*
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.
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
209
*/
21-
2210
namespace WikibaseSolutions\CypherDSL\Expressions;
2311

2412
use WikibaseSolutions\CypherDSL\Clauses\MatchClause;
2513
use WikibaseSolutions\CypherDSL\Clauses\WhereClause;
14+
use WikibaseSolutions\CypherDSL\Patterns\MatchablePattern;
15+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2616
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\PropertyTypeTraits\BooleanTypeTrait;
2717
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
18+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2819

2920
/**
3021
* Represents the EXISTS expression.
@@ -33,6 +24,7 @@
3324
*/
3425
final class Exists implements BooleanType
3526
{
27+
use ErrorTrait;
3628
use BooleanTypeTrait;
3729

3830
/**
@@ -51,13 +43,12 @@ final class Exists implements BooleanType
5143
private bool $insertParentheses;
5244

5345
/**
54-
* Exists constructor.
55-
*
5646
* @param MatchClause $match The MATCH part of the EXISTS expression
5747
* @param WhereClause|null $where The optional WHERE part of the EXISTS expression
5848
* @param bool $insertParentheses Whether to insert parentheses around the expression
49+
* @internal This function is not covered by the backwards compatibility guarantee of php-cypher-dsl
5950
*/
60-
public function __construct(MatchClause $match, ?WhereClause $where = null, bool $insertParentheses = false)
51+
public function __construct(MatchClause $match, WhereClause $where = null, bool $insertParentheses = false)
6152
{
6253
$this->match = $match;
6354
$this->where = $where;

src/Expressions/Label.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
<?php
2-
1+
<?php declare(strict_types=1);
32
/*
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.
3+
* This file is part of php-cypher-dsl.
114
*
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.
5+
* Copyright (C) 2021 Wikibase Solutions
166
*
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.
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
209
*/
21-
2210
namespace WikibaseSolutions\CypherDSL\Expressions;
2311

2412
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
@@ -55,6 +43,7 @@ final class Label implements BooleanType
5543
*
5644
* @param Variable $variable The variable to attach the labels to
5745
* @param string ...$labels The labels to attach to the variable
46+
* @internal This function is not covered by the backwards compatibility guarantee of php-cypher-dsl
5847
*/
5948
public function __construct(Variable $variable, string ...$labels)
6049
{

src/Expressions/Literals/Float_.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of php-cypher-dsl.
4+
*
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace WikibaseSolutions\CypherDSL\Expressions\Literals;
11+
12+
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\PropertyTypeTraits\FloatTypeTrait;
13+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\FloatType;
14+
15+
/**
16+
* Represents a float literal.
17+
*/
18+
final class Float_ implements FloatType
19+
{
20+
use FloatTypeTrait;
21+
22+
/**
23+
* @var float The value
24+
*/
25+
private float $value;
26+
27+
/**
28+
* @param float $value The value
29+
* @internal This function is not covered by the backwards compatibility guarantee of php-cypher-dsl
30+
*/
31+
public function __construct(float $value)
32+
{
33+
$this->value = $value;
34+
}
35+
36+
/**
37+
* Returns the integer value.
38+
*
39+
* @return float
40+
*/
41+
public function getValue(): float
42+
{
43+
return $this->value;
44+
}
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
public function toQuery(): string
50+
{
51+
return (string)$this->value;
52+
}
53+
}

src/Expressions/Literals/Decimal.php renamed to src/Expressions/Literals/Integer.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,36 @@
99
*/
1010
namespace WikibaseSolutions\CypherDSL\Expressions\Literals;
1111

12-
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
13-
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\PropertyTypeTraits\NumeralTypeTrait;
14-
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
12+
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\PropertyTypeTraits\IntegerTypeTrait;
13+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\IntegerType;
1514

1615
/**
17-
* Represents a decimal (integer or float) literal.
16+
* Represents an integer literal.
1817
*/
19-
final class Decimal implements NumeralType
18+
final class Integer implements IntegerType
2019
{
21-
use NumeralTypeTrait;
22-
23-
use ErrorTrait;
20+
use IntegerTypeTrait;
2421

2522
/**
26-
* @var int|float The value
23+
* @var int The value
2724
*/
28-
private $value;
25+
private int $value;
2926

3027
/**
31-
* @param int|float $value The value
28+
* @param int $value The value
3229
* @internal This function is not covered by the backwards compatibility guarantee of php-cypher-dsl
3330
*/
34-
public function __construct($value)
31+
public function __construct(int $value)
3532
{
36-
$this->assertClass('value', ['int', 'float'], $value);
3733
$this->value = $value;
3834
}
3935

4036
/**
41-
* Returns the numeric value.
37+
* Returns the integer value.
4238
*
43-
* @return int|float
39+
* @return int
4440
*/
45-
public function getValue()
41+
public function getValue(): int
4642
{
4743
return $this->value;
4844
}

0 commit comments

Comments
 (0)