Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
39dd1e53
Commit
39dd1e53
authored
Jan 31, 2020
by
Benjamin Morel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow empty CompositeExpression
parent
97e0c2bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
34 deletions
+20
-34
CompositeExpression.php
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
+7
-11
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+2
-2
CompositeExpressionTest.php
...e/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
+11
-21
No files found.
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
View file @
39dd1e53
...
@@ -5,9 +5,7 @@ declare(strict_types=1);
...
@@ -5,9 +5,7 @@ declare(strict_types=1);
namespace
Doctrine\DBAL\Query\Expression
;
namespace
Doctrine\DBAL\Query\Expression
;
use
Countable
;
use
Countable
;
use
function
array_filter
;
use
function
array_merge
;
use
function
array_merge
;
use
function
array_values
;
use
function
count
;
use
function
count
;
use
function
implode
;
use
function
implode
;
...
@@ -38,22 +36,20 @@ class CompositeExpression implements Countable
...
@@ -38,22 +36,20 @@ class CompositeExpression implements Countable
/**
/**
* Each expression part of the composite expression.
* Each expression part of the composite expression.
*
*
* @var
self[]|string[]
* @var
array<int, self|string>
*/
*/
private
$parts
=
[];
private
$parts
=
[];
/**
/**
* @internal Use the and() / or() factory methods.
* @internal Use the and() / or() factory methods.
*
*
* @param s
tring $type Instance type of composite expression.
* @param s
elf|string $part
* @param self
[]|string[] $parts Composition of expressions to be joined on composite expression.
* @param self
|string ...$parts
*/
*/
public
function
__construct
(
string
$type
,
array
$parts
=
[]
)
public
function
__construct
(
string
$type
,
$part
,
...
$parts
)
{
{
$this
->
type
=
$type
;
$this
->
type
=
$type
;
$this
->
parts
=
array_values
(
array_filter
(
$parts
,
static
function
(
$part
)
{
$this
->
parts
=
array_merge
([
$part
],
$parts
);
return
!
(
$part
instanceof
self
&&
count
(
$part
)
===
0
);
}));
}
}
/**
/**
...
@@ -62,7 +58,7 @@ class CompositeExpression implements Countable
...
@@ -62,7 +58,7 @@ class CompositeExpression implements Countable
*/
*/
public
static
function
and
(
$part
,
...
$parts
)
:
self
public
static
function
and
(
$part
,
...
$parts
)
:
self
{
{
return
new
self
(
self
::
TYPE_AND
,
array_merge
([
$part
],
$parts
)
);
return
new
self
(
self
::
TYPE_AND
,
$part
,
...
$parts
);
}
}
/**
/**
...
@@ -71,7 +67,7 @@ class CompositeExpression implements Countable
...
@@ -71,7 +67,7 @@ class CompositeExpression implements Countable
*/
*/
public
static
function
or
(
$part
,
...
$parts
)
:
self
public
static
function
or
(
$part
,
...
$parts
)
:
self
{
{
return
new
self
(
self
::
TYPE_OR
,
array_merge
([
$part
],
$parts
)
);
return
new
self
(
self
::
TYPE_OR
,
$part
,
...
$parts
);
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
39dd1e53
...
@@ -1025,7 +1025,7 @@ class QueryBuilder
...
@@ -1025,7 +1025,7 @@ class QueryBuilder
return
$predicate
;
return
$predicate
;
}
}
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
array_merge
([
$predicate
],
$predicates
)
);
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
$predicate
,
...
$predicates
);
}
}
/**
/**
...
@@ -1048,7 +1048,7 @@ class QueryBuilder
...
@@ -1048,7 +1048,7 @@ class QueryBuilder
return
$predicates
[
0
];
return
$predicates
[
0
];
}
}
return
new
CompositeExpression
(
$type
,
$predicates
);
return
new
CompositeExpression
(
$type
,
...
$predicates
);
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
View file @
39dd1e53
...
@@ -44,14 +44,10 @@ class CompositeExpressionTest extends DbalTestCase
...
@@ -44,14 +44,10 @@ class CompositeExpressionTest extends DbalTestCase
}
}
/**
/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForConvertToString
* @dataProvider provideDataForConvertToString
*/
*/
public
function
testCompositeUsageAndGeneration
(
string
$type
,
array
$parts
,
string
$expects
)
:
void
public
function
testCompositeUsageAndGeneration
(
CompositeExpression
$expr
,
string
$expects
)
:
void
{
{
$expr
=
new
CompositeExpression
(
$type
,
$parts
);
self
::
assertEquals
(
$expects
,
(
string
)
$expr
);
self
::
assertEquals
(
$expects
,
(
string
)
$expr
);
}
}
...
@@ -62,45 +58,39 @@ class CompositeExpressionTest extends DbalTestCase
...
@@ -62,45 +58,39 @@ class CompositeExpressionTest extends DbalTestCase
{
{
return
[
return
[
[
[
CompositeExpression
::
TYPE_AND
,
CompositeExpression
::
and
(
'u.user = 1'
),
[
'u.user = 1'
],
'u.user = 1'
,
'u.user = 1'
,
],
],
[
[
CompositeExpression
::
TYPE_AND
,
CompositeExpression
::
and
(
'u.user = 1'
,
'u.group_id = 1'
),
[
'u.user = 1'
,
'u.group_id = 1'
],
'(u.user = 1) AND (u.group_id = 1)'
,
'(u.user = 1) AND (u.group_id = 1)'
,
],
],
[
[
CompositeExpression
::
TYPE_OR
,
CompositeExpression
::
or
(
'u.user = 1'
),
[
'u.user = 1'
],
'u.user = 1'
,
'u.user = 1'
,
],
],
[
[
CompositeExpression
::
TYPE_OR
,
CompositeExpression
::
or
(
'u.group_id = 1'
,
'u.group_id = 2'
),
[
'u.group_id = 1'
,
'u.group_id = 2'
],
'(u.group_id = 1) OR (u.group_id = 2)'
,
'(u.group_id = 1) OR (u.group_id = 2)'
,
],
],
[
[
CompositeExpression
::
TYPE_AND
,
CompositeExpression
::
and
(
[
'u.user = 1'
,
'u.user = 1'
,
CompositeExpression
::
or
(
CompositeExpression
::
or
(
'u.group_id = 1'
,
'u.group_id = 1'
,
'u.group_id = 2'
'u.group_id = 2'
)
,
)
]
,
)
,
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))'
,
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))'
,
],
],
[
[
CompositeExpression
::
TYPE_OR
,
CompositeExpression
::
or
(
[
'u.group_id = 1'
,
'u.group_id = 1'
,
CompositeExpression
::
and
(
CompositeExpression
::
and
(
'u.user = 1'
,
'u.user = 1'
,
'u.group_id = 2'
'u.group_id = 2'
)
,
)
]
,
)
,
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))'
,
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))'
,
],
],
];
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment