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
598bcfd7
Unverified
Commit
598bcfd7
authored
May 30, 2019
by
Jonathan H. Wage
Committed by
Sergei Morozov
Nov 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add proper types to Doctrine\DBAL\Query namespace.
parent
77d3dfa3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
160 deletions
+97
-160
CompositeExpression.php
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
+10
-16
ExpressionBuilder.php
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
+16
-46
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+71
-98
No files found.
lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
View file @
598bcfd7
...
@@ -41,7 +41,7 @@ class CompositeExpression implements Countable
...
@@ -41,7 +41,7 @@ class CompositeExpression implements Countable
* @param string $type Instance type of composite expression.
* @param string $type Instance type of composite expression.
* @param self[]|string[] $parts Composition of expressions to be joined on composite expression.
* @param self[]|string[] $parts Composition of expressions to be joined on composite expression.
*/
*/
public
function
__construct
(
$type
,
array
$parts
=
[])
public
function
__construct
(
string
$type
,
array
$parts
=
[])
{
{
$this
->
type
=
$type
;
$this
->
type
=
$type
;
...
@@ -51,11 +51,11 @@ class CompositeExpression implements Countable
...
@@ -51,11 +51,11 @@ class CompositeExpression implements Countable
/**
/**
* Adds multiple parts to composite expression.
* Adds multiple parts to composite expression.
*
*
* @param
self[]|string[]
$parts
* @param
array<int, self|string>
$parts
*
*
* @return
\Doctrine\DBAL\Query\Expression\CompositeExpression
* @return
$this
*/
*/
public
function
addMultiple
(
array
$parts
=
[])
public
function
addMultiple
(
array
$parts
=
[])
:
self
{
{
foreach
(
$parts
as
$part
)
{
foreach
(
$parts
as
$part
)
{
$this
->
add
(
$part
);
$this
->
add
(
$part
);
...
@@ -67,11 +67,11 @@ class CompositeExpression implements Countable
...
@@ -67,11 +67,11 @@ class CompositeExpression implements Countable
/**
/**
* Adds an expression to composite expression.
* Adds an expression to composite expression.
*
*
* @param
mixed
$part
* @param
self|string
$part
*
*
* @return
\Doctrine\DBAL\Query\Expression\CompositeExpression
* @return
$this
*/
*/
public
function
add
(
$part
)
public
function
add
(
$part
)
:
self
{
{
if
(
empty
(
$part
))
{
if
(
empty
(
$part
))
{
return
$this
;
return
$this
;
...
@@ -88,20 +88,16 @@ class CompositeExpression implements Countable
...
@@ -88,20 +88,16 @@ class CompositeExpression implements Countable
/**
/**
* Retrieves the amount of expressions on composite expression.
* Retrieves the amount of expressions on composite expression.
*
* @return int
*/
*/
public
function
count
()
public
function
count
()
:
int
{
{
return
count
(
$this
->
parts
);
return
count
(
$this
->
parts
);
}
}
/**
/**
* Retrieves the string representation of this composite expression.
* Retrieves the string representation of this composite expression.
*
* @return string
*/
*/
public
function
__toString
()
public
function
__toString
()
:
string
{
{
if
(
$this
->
count
()
===
1
)
{
if
(
$this
->
count
()
===
1
)
{
return
(
string
)
$this
->
parts
[
0
];
return
(
string
)
$this
->
parts
[
0
];
...
@@ -112,10 +108,8 @@ class CompositeExpression implements Countable
...
@@ -112,10 +108,8 @@ class CompositeExpression implements Countable
/**
/**
* Returns the type of this composite expression (AND/OR).
* Returns the type of this composite expression (AND/OR).
*
* @return string
*/
*/
public
function
getType
()
public
function
getType
()
:
string
{
{
return
$this
->
type
;
return
$this
->
type
;
}
}
...
...
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
View file @
598bcfd7
...
@@ -51,10 +51,8 @@ class ExpressionBuilder
...
@@ -51,10 +51,8 @@ class ExpressionBuilder
*
*
* @param mixed $x Optional clause. Defaults = null, but requires
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* at least one defined when converting to string.
*
* @return CompositeExpression
*/
*/
public
function
andX
(
$x
=
null
)
public
function
andX
(
$x
=
null
)
:
CompositeExpression
{
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
func_get_args
());
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
func_get_args
());
}
}
...
@@ -70,10 +68,8 @@ class ExpressionBuilder
...
@@ -70,10 +68,8 @@ class ExpressionBuilder
*
*
* @param mixed $x Optional clause. Defaults = null, but requires
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* at least one defined when converting to string.
*
* @return CompositeExpression
*/
*/
public
function
orX
(
$x
=
null
)
public
function
orX
(
$x
=
null
)
:
CompositeExpression
{
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
func_get_args
());
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
func_get_args
());
}
}
...
@@ -84,10 +80,8 @@ class ExpressionBuilder
...
@@ -84,10 +80,8 @@ class ExpressionBuilder
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param string $operator One of the ExpressionBuilder::* constants.
* @param string $operator One of the ExpressionBuilder::* constants.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
comparison
(
$x
,
$operator
,
$y
)
public
function
comparison
(
$x
,
string
$operator
,
$y
)
:
string
{
{
return
$x
.
' '
.
$operator
.
' '
.
$y
;
return
$x
.
' '
.
$operator
.
' '
.
$y
;
}
}
...
@@ -104,10 +98,8 @@ class ExpressionBuilder
...
@@ -104,10 +98,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
eq
(
$x
,
$y
)
public
function
eq
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
EQ
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
EQ
,
$y
);
}
}
...
@@ -123,10 +115,8 @@ class ExpressionBuilder
...
@@ -123,10 +115,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
neq
(
$x
,
$y
)
public
function
neq
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
NEQ
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
NEQ
,
$y
);
}
}
...
@@ -142,10 +132,8 @@ class ExpressionBuilder
...
@@ -142,10 +132,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
lt
(
$x
,
$y
)
public
function
lt
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
LT
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
LT
,
$y
);
}
}
...
@@ -161,10 +149,8 @@ class ExpressionBuilder
...
@@ -161,10 +149,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
lte
(
$x
,
$y
)
public
function
lte
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
LTE
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
LTE
,
$y
);
}
}
...
@@ -180,10 +166,8 @@ class ExpressionBuilder
...
@@ -180,10 +166,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
gt
(
$x
,
$y
)
public
function
gt
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
GT
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
GT
,
$y
);
}
}
...
@@ -199,10 +183,8 @@ class ExpressionBuilder
...
@@ -199,10 +183,8 @@ class ExpressionBuilder
*
*
* @param mixed $x The left expression.
* @param mixed $x The left expression.
* @param mixed $y The right expression.
* @param mixed $y The right expression.
*
* @return string
*/
*/
public
function
gte
(
$x
,
$y
)
public
function
gte
(
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
self
::
GTE
,
$y
);
return
$this
->
comparison
(
$x
,
self
::
GTE
,
$y
);
}
}
...
@@ -211,10 +193,8 @@ class ExpressionBuilder
...
@@ -211,10 +193,8 @@ class ExpressionBuilder
* Creates an IS NULL expression with the given arguments.
* Creates an IS NULL expression with the given arguments.
*
*
* @param string $x The field in string format to be restricted by IS NULL.
* @param string $x The field in string format to be restricted by IS NULL.
*
* @return string
*/
*/
public
function
isNull
(
$x
)
public
function
isNull
(
string
$x
)
:
string
{
{
return
$x
.
' IS NULL'
;
return
$x
.
' IS NULL'
;
}
}
...
@@ -223,10 +203,8 @@ class ExpressionBuilder
...
@@ -223,10 +203,8 @@ class ExpressionBuilder
* Creates an IS NOT NULL expression with the given arguments.
* Creates an IS NOT NULL expression with the given arguments.
*
*
* @param string $x The field in string format to be restricted by IS NOT NULL.
* @param string $x The field in string format to be restricted by IS NOT NULL.
*
* @return string
*/
*/
public
function
isNotNull
(
$x
)
public
function
isNotNull
(
string
$x
)
:
string
{
{
return
$x
.
' IS NOT NULL'
;
return
$x
.
' IS NOT NULL'
;
}
}
...
@@ -236,10 +214,8 @@ class ExpressionBuilder
...
@@ -236,10 +214,8 @@ class ExpressionBuilder
*
*
* @param string $x Field in string format to be inspected by LIKE() comparison.
* @param string $x Field in string format to be inspected by LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison.
* @param mixed $y Argument to be used in LIKE() comparison.
*
* @return string
*/
*/
public
function
like
(
$x
,
$y
/*, ?string $escapeChar = null */
)
public
function
like
(
string
$x
,
$y
/*, ?string $escapeChar = null */
)
:
string
{
{
return
$this
->
comparison
(
$x
,
'LIKE'
,
$y
)
.
return
$this
->
comparison
(
$x
,
'LIKE'
,
$y
)
.
(
func_num_args
()
>=
3
?
sprintf
(
' ESCAPE %s'
,
func_get_arg
(
2
))
:
''
);
(
func_num_args
()
>=
3
?
sprintf
(
' ESCAPE %s'
,
func_get_arg
(
2
))
:
''
);
...
@@ -250,10 +226,8 @@ class ExpressionBuilder
...
@@ -250,10 +226,8 @@ class ExpressionBuilder
*
*
* @param string $x Field in string format to be inspected by NOT LIKE() comparison.
* @param string $x Field in string format to be inspected by NOT LIKE() comparison.
* @param mixed $y Argument to be used in NOT LIKE() comparison.
* @param mixed $y Argument to be used in NOT LIKE() comparison.
*
* @return string
*/
*/
public
function
notLike
(
$x
,
$y
/*, ?string $escapeChar = null */
)
public
function
notLike
(
string
$x
,
$y
/*, ?string $escapeChar = null */
)
:
string
{
{
return
$this
->
comparison
(
$x
,
'NOT LIKE'
,
$y
)
.
return
$this
->
comparison
(
$x
,
'NOT LIKE'
,
$y
)
.
(
func_num_args
()
>=
3
?
sprintf
(
' ESCAPE %s'
,
func_get_arg
(
2
))
:
''
);
(
func_num_args
()
>=
3
?
sprintf
(
' ESCAPE %s'
,
func_get_arg
(
2
))
:
''
);
...
@@ -264,10 +238,8 @@ class ExpressionBuilder
...
@@ -264,10 +238,8 @@ class ExpressionBuilder
*
*
* @param string $x The field in string format to be inspected by IN() comparison.
* @param string $x The field in string format to be inspected by IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by IN() comparison.
*
* @return string
*/
*/
public
function
in
(
$x
,
$y
)
public
function
in
(
string
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
'IN'
,
'('
.
implode
(
', '
,
(
array
)
$y
)
.
')'
);
return
$this
->
comparison
(
$x
,
'IN'
,
'('
.
implode
(
', '
,
(
array
)
$y
)
.
')'
);
}
}
...
@@ -277,10 +249,8 @@ class ExpressionBuilder
...
@@ -277,10 +249,8 @@ class ExpressionBuilder
*
*
* @param string $x The field in string format to be inspected by NOT IN() comparison.
* @param string $x The field in string format to be inspected by NOT IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison.
* @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison.
*
* @return string
*/
*/
public
function
notIn
(
$x
,
$y
)
public
function
notIn
(
string
$x
,
$y
)
:
string
{
{
return
$this
->
comparison
(
$x
,
'NOT IN'
,
'('
.
implode
(
', '
,
(
array
)
$y
)
.
')'
);
return
$this
->
comparison
(
$x
,
'NOT IN'
,
'('
.
implode
(
', '
,
(
array
)
$y
)
.
')'
);
}
}
...
@@ -288,7 +258,7 @@ class ExpressionBuilder
...
@@ -288,7 +258,7 @@ class ExpressionBuilder
/**
/**
* Creates an SQL literal expression from the string.
* Creates an SQL literal expression from the string.
*/
*/
public
function
literal
(
string
$input
)
public
function
literal
(
string
$input
)
:
string
{
{
return
$this
->
connection
->
quote
(
$input
);
return
$this
->
connection
->
quote
(
$input
);
}
}
...
...
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
598bcfd7
...
@@ -75,7 +75,7 @@ class QueryBuilder
...
@@ -75,7 +75,7 @@ class QueryBuilder
/**
/**
* The array of SQL parts collected.
* The array of SQL parts collected.
*
*
* @var
mixed[]
* @var
array<string, mixed>
*/
*/
private
$sqlParts
=
self
::
SQL_PARTS_DEFAULTS
;
private
$sqlParts
=
self
::
SQL_PARTS_DEFAULTS
;
...
@@ -89,14 +89,14 @@ class QueryBuilder
...
@@ -89,14 +89,14 @@ class QueryBuilder
/**
/**
* The query parameters.
* The query parameters.
*
*
* @var
mixed[]
* @var
array<int, mixed>|array<string, mixed>
*/
*/
private
$params
=
[];
private
$params
=
[];
/**
/**
* The parameter type map of this query.
* The parameter type map of this query.
*
*
* @var
int[]|string[]
* @var
array<int, mixed>|array<string, mixed>
*/
*/
private
$paramTypes
=
[];
private
$paramTypes
=
[];
...
@@ -119,14 +119,14 @@ class QueryBuilder
...
@@ -119,14 +119,14 @@ class QueryBuilder
*
*
* @var int
* @var int
*/
*/
private
$firstResult
=
null
;
private
$firstResult
=
0
;
/**
/**
* The maximum number of results to retrieve.
* The maximum number of results to retrieve.
*
*
* @var int
* @var int
|null
*/
*/
private
$maxResults
=
null
;
private
$maxResults
;
/**
/**
* The counter of bound parameters used with {@see bindValue).
* The counter of bound parameters used with {@see bindValue).
...
@@ -158,30 +158,24 @@ class QueryBuilder
...
@@ -158,30 +158,24 @@ class QueryBuilder
*
*
* For more complex expression construction, consider storing the expression
* For more complex expression construction, consider storing the expression
* builder object in a local variable.
* builder object in a local variable.
*
* @return ExpressionBuilder
*/
*/
public
function
expr
()
public
function
expr
()
:
ExpressionBuilder
{
{
return
$this
->
connection
->
getExpressionBuilder
();
return
$this
->
connection
->
getExpressionBuilder
();
}
}
/**
/**
* Gets the type of the currently built query.
* Gets the type of the currently built query.
*
* @return int
*/
*/
public
function
getType
()
public
function
getType
()
:
int
{
{
return
$this
->
type
;
return
$this
->
type
;
}
}
/**
/**
* Gets the associated DBAL Connection for this query builder.
* Gets the associated DBAL Connection for this query builder.
*
* @return Connection
*/
*/
public
function
getConnection
()
public
function
getConnection
()
:
Connection
{
{
return
$this
->
connection
;
return
$this
->
connection
;
}
}
...
@@ -191,7 +185,7 @@ class QueryBuilder
...
@@ -191,7 +185,7 @@ class QueryBuilder
*
*
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
*/
*/
public
function
getState
()
public
function
getState
()
:
int
{
{
return
$this
->
state
;
return
$this
->
state
;
}
}
...
@@ -225,7 +219,7 @@ class QueryBuilder
...
@@ -225,7 +219,7 @@ class QueryBuilder
*
*
* @return string The SQL query string.
* @return string The SQL query string.
*/
*/
public
function
getSQL
()
public
function
getSQL
()
:
string
{
{
if
(
$this
->
sql
!==
null
&&
$this
->
state
===
self
::
STATE_CLEAN
)
{
if
(
$this
->
sql
!==
null
&&
$this
->
state
===
self
::
STATE_CLEAN
)
{
return
$this
->
sql
;
return
$this
->
sql
;
...
@@ -272,7 +266,7 @@ class QueryBuilder
...
@@ -272,7 +266,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
setParameter
(
$key
,
$value
,
$type
=
null
)
public
function
setParameter
(
$key
,
$value
,
$type
=
null
)
:
self
{
{
if
(
$type
!==
null
)
{
if
(
$type
!==
null
)
{
$this
->
paramTypes
[
$key
]
=
$type
;
$this
->
paramTypes
[
$key
]
=
$type
;
...
@@ -297,12 +291,12 @@ class QueryBuilder
...
@@ -297,12 +291,12 @@ class QueryBuilder
* ));
* ));
* </code>
* </code>
*
*
* @param
mixed[]
$params The query parameters to set.
* @param
array<int, mixed>|array<string, mixed>
$params The query parameters to set.
* @param
int[]|string[]
$types The query parameters types to set.
* @param
array<int, mixed>|array<string, mixed>
$types The query parameters types to set.
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
setParameters
(
array
$params
,
array
$types
=
[])
public
function
setParameters
(
array
$params
,
array
$types
=
[])
:
self
{
{
$this
->
paramTypes
=
$types
;
$this
->
paramTypes
=
$types
;
$this
->
params
=
$params
;
$this
->
params
=
$params
;
...
@@ -313,9 +307,9 @@ class QueryBuilder
...
@@ -313,9 +307,9 @@ class QueryBuilder
/**
/**
* Gets all defined query parameters for the query being constructed indexed by parameter index or name.
* Gets all defined query parameters for the query being constructed indexed by parameter index or name.
*
*
* @return
mixed[]
The currently defined query parameters indexed by parameter index or name.
* @return
array<string|int, mixed>
The currently defined query parameters indexed by parameter index or name.
*/
*/
public
function
getParameters
()
public
function
getParameters
()
:
array
{
{
return
$this
->
params
;
return
$this
->
params
;
}
}
...
@@ -323,7 +317,7 @@ class QueryBuilder
...
@@ -323,7 +317,7 @@ class QueryBuilder
/**
/**
* Gets a (previously set) query parameter of the query being constructed.
* Gets a (previously set) query parameter of the query being constructed.
*
*
* @param
mixed
$key The key (index or name) of the bound parameter.
* @param
string|int
$key The key (index or name) of the bound parameter.
*
*
* @return mixed The value of the bound parameter.
* @return mixed The value of the bound parameter.
*/
*/
...
@@ -335,9 +329,9 @@ class QueryBuilder
...
@@ -335,9 +329,9 @@ class QueryBuilder
/**
/**
* Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
* Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
*
*
* @return
int[]|string[]
The currently defined query parameter types indexed by parameter index or name.
* @return
array<string|int, mixed>
The currently defined query parameter types indexed by parameter index or name.
*/
*/
public
function
getParameterTypes
()
public
function
getParameterTypes
()
:
array
{
{
return
$this
->
paramTypes
;
return
$this
->
paramTypes
;
}
}
...
@@ -345,7 +339,7 @@ class QueryBuilder
...
@@ -345,7 +339,7 @@ class QueryBuilder
/**
/**
* Gets a (previously set) query parameter type of the query being constructed.
* Gets a (previously set) query parameter type of the query being constructed.
*
*
* @param
mixed
$key The key (index or name) of the bound parameter type.
* @param
string|int
$key The key (index or name) of the bound parameter type.
*
*
* @return mixed The value of the bound parameter type.
* @return mixed The value of the bound parameter type.
*/
*/
...
@@ -361,7 +355,7 @@ class QueryBuilder
...
@@ -361,7 +355,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
setFirstResult
(
$firstResult
)
public
function
setFirstResult
(
int
$firstResult
)
:
self
{
{
$this
->
state
=
self
::
STATE_DIRTY
;
$this
->
state
=
self
::
STATE_DIRTY
;
$this
->
firstResult
=
$firstResult
;
$this
->
firstResult
=
$firstResult
;
...
@@ -375,7 +369,7 @@ class QueryBuilder
...
@@ -375,7 +369,7 @@ class QueryBuilder
*
*
* @return int The position of the first result.
* @return int The position of the first result.
*/
*/
public
function
getFirstResult
()
public
function
getFirstResult
()
:
int
{
{
return
$this
->
firstResult
;
return
$this
->
firstResult
;
}
}
...
@@ -387,7 +381,7 @@ class QueryBuilder
...
@@ -387,7 +381,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
setMaxResults
(
$maxResults
)
public
function
setMaxResults
(
int
$maxResults
)
:
self
{
{
$this
->
state
=
self
::
STATE_DIRTY
;
$this
->
state
=
self
::
STATE_DIRTY
;
$this
->
maxResults
=
$maxResults
;
$this
->
maxResults
=
$maxResults
;
...
@@ -401,7 +395,7 @@ class QueryBuilder
...
@@ -401,7 +395,7 @@ class QueryBuilder
*
*
* @return int The maximum number of results.
* @return int The maximum number of results.
*/
*/
public
function
getMaxResults
()
public
function
getMaxResults
()
:
int
{
{
return
$this
->
maxResults
;
return
$this
->
maxResults
;
}
}
...
@@ -412,13 +406,11 @@ class QueryBuilder
...
@@ -412,13 +406,11 @@ class QueryBuilder
* The available parts are: 'select', 'from', 'set', 'where',
* The available parts are: 'select', 'from', 'set', 'where',
* 'groupBy', 'having' and 'orderBy'.
* 'groupBy', 'having' and 'orderBy'.
*
*
* @param string $sqlPartName
* @param mixed $sqlPart
* @param mixed $sqlPart
* @param bool $append
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
add
(
$sqlPartName
,
$sqlPart
,
$append
=
false
)
public
function
add
(
string
$sqlPartName
,
$sqlPart
,
bool
$append
=
false
)
:
self
{
{
$isArray
=
is_array
(
$sqlPart
);
$isArray
=
is_array
(
$sqlPart
);
$isMultiple
=
is_array
(
$this
->
sqlParts
[
$sqlPartName
]);
$isMultiple
=
is_array
(
$this
->
sqlParts
[
$sqlPartName
]);
...
@@ -466,7 +458,7 @@ class QueryBuilder
...
@@ -466,7 +458,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
select
(
$select
=
null
)
public
function
select
(
$select
=
null
)
:
self
{
{
$this
->
type
=
self
::
SELECT
;
$this
->
type
=
self
::
SELECT
;
...
@@ -513,7 +505,7 @@ class QueryBuilder
...
@@ -513,7 +505,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
addSelect
(
$select
=
null
)
public
function
addSelect
(
$select
=
null
)
:
self
{
{
$this
->
type
=
self
::
SELECT
;
$this
->
type
=
self
::
SELECT
;
...
@@ -542,7 +534,7 @@ class QueryBuilder
...
@@ -542,7 +534,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
delete
(
$delete
=
null
,
$alias
=
null
)
public
function
delete
(
?
string
$delete
=
null
,
?
string
$alias
=
null
)
:
self
{
{
$this
->
type
=
self
::
DELETE
;
$this
->
type
=
self
::
DELETE
;
...
@@ -572,7 +564,7 @@ class QueryBuilder
...
@@ -572,7 +564,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
update
(
$update
=
null
,
$alias
=
null
)
public
function
update
(
?
string
$update
=
null
,
?
string
$alias
=
null
)
:
self
{
{
$this
->
type
=
self
::
UPDATE
;
$this
->
type
=
self
::
UPDATE
;
...
@@ -605,7 +597,7 @@ class QueryBuilder
...
@@ -605,7 +597,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
insert
(
$insert
=
null
)
public
function
insert
(
?
string
$insert
=
null
)
:
self
{
{
$this
->
type
=
self
::
INSERT
;
$this
->
type
=
self
::
INSERT
;
...
@@ -631,7 +623,7 @@ class QueryBuilder
...
@@ -631,7 +623,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
from
(
$from
,
$alias
=
null
)
public
function
from
(
string
$from
,
?
string
$alias
=
null
)
{
{
return
$this
->
add
(
'from'
,
[
return
$this
->
add
(
'from'
,
[
'table'
=>
$from
,
'table'
=>
$from
,
...
@@ -656,7 +648,7 @@ class QueryBuilder
...
@@ -656,7 +648,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
join
(
$fromAlias
,
$join
,
$alias
,
$condition
=
null
)
public
function
join
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
{
return
$this
->
innerJoin
(
$fromAlias
,
$join
,
$alias
,
$condition
);
return
$this
->
innerJoin
(
$fromAlias
,
$join
,
$alias
,
$condition
);
}
}
...
@@ -678,7 +670,7 @@ class QueryBuilder
...
@@ -678,7 +670,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
innerJoin
(
$fromAlias
,
$join
,
$alias
,
$condition
=
null
)
public
function
innerJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
{
return
$this
->
add
(
'join'
,
[
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
$fromAlias
=>
[
...
@@ -707,7 +699,7 @@ class QueryBuilder
...
@@ -707,7 +699,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
leftJoin
(
$fromAlias
,
$join
,
$alias
,
$condition
=
null
)
public
function
leftJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
{
return
$this
->
add
(
'join'
,
[
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
$fromAlias
=>
[
...
@@ -736,7 +728,7 @@ class QueryBuilder
...
@@ -736,7 +728,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
rightJoin
(
$fromAlias
,
$join
,
$alias
,
$condition
=
null
)
public
function
rightJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
{
return
$this
->
add
(
'join'
,
[
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
$fromAlias
=>
[
...
@@ -763,7 +755,7 @@ class QueryBuilder
...
@@ -763,7 +755,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
set
(
$key
,
$value
)
public
function
set
(
string
$key
,
string
$value
)
{
{
return
$this
->
add
(
'set'
,
$key
.
' = '
.
$value
,
true
);
return
$this
->
add
(
'set'
,
$key
.
' = '
.
$value
,
true
);
}
}
...
@@ -884,7 +876,7 @@ class QueryBuilder
...
@@ -884,7 +876,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
groupBy
(
$groupBy
)
public
function
groupBy
(
$groupBy
)
:
self
{
{
if
(
empty
(
$groupBy
))
{
if
(
empty
(
$groupBy
))
{
return
$this
;
return
$this
;
...
@@ -910,7 +902,7 @@ class QueryBuilder
...
@@ -910,7 +902,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
addGroupBy
(
$groupBy
)
public
function
addGroupBy
(
$groupBy
)
:
self
{
{
if
(
empty
(
$groupBy
))
{
if
(
empty
(
$groupBy
))
{
return
$this
;
return
$this
;
...
@@ -940,7 +932,7 @@ class QueryBuilder
...
@@ -940,7 +932,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
setValue
(
$column
,
$value
)
public
function
setValue
(
string
$column
,
string
$value
)
:
self
{
{
$this
->
sqlParts
[
'values'
][
$column
]
=
$value
;
$this
->
sqlParts
[
'values'
][
$column
]
=
$value
;
...
@@ -962,7 +954,7 @@ class QueryBuilder
...
@@ -962,7 +954,7 @@ class QueryBuilder
* );
* );
* </code>
* </code>
*
*
* @param
mixed[]
$values The values to specify for the insert query indexed by column names.
* @param
array<int, mixed>
$values The values to specify for the insert query indexed by column names.
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
...
@@ -1043,7 +1035,7 @@ class QueryBuilder
...
@@ -1043,7 +1035,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
orderBy
(
$sort
,
$order
=
null
)
public
function
orderBy
(
string
$sort
,
?
string
$order
=
null
)
{
{
return
$this
->
add
(
'orderBy'
,
$sort
.
' '
.
(
!
$order
?
'ASC'
:
$order
),
false
);
return
$this
->
add
(
'orderBy'
,
$sort
.
' '
.
(
!
$order
?
'ASC'
:
$order
),
false
);
}
}
...
@@ -1056,7 +1048,7 @@ class QueryBuilder
...
@@ -1056,7 +1048,7 @@ class QueryBuilder
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
addOrderBy
(
$sort
,
$order
=
null
)
public
function
addOrderBy
(
string
$sort
,
?
string
$order
=
null
)
{
{
return
$this
->
add
(
'orderBy'
,
$sort
.
' '
.
(
!
$order
?
'ASC'
:
$order
),
true
);
return
$this
->
add
(
'orderBy'
,
$sort
.
' '
.
(
!
$order
?
'ASC'
:
$order
),
true
);
}
}
...
@@ -1064,11 +1056,9 @@ class QueryBuilder
...
@@ -1064,11 +1056,9 @@ class QueryBuilder
/**
/**
* Gets a query part by its name.
* Gets a query part by its name.
*
*
* @param string $queryPartName
*
* @return mixed
* @return mixed
*/
*/
public
function
getQueryPart
(
$queryPartName
)
public
function
getQueryPart
(
string
$queryPartName
)
{
{
return
$this
->
sqlParts
[
$queryPartName
];
return
$this
->
sqlParts
[
$queryPartName
];
}
}
...
@@ -1076,9 +1066,9 @@ class QueryBuilder
...
@@ -1076,9 +1066,9 @@ class QueryBuilder
/**
/**
* Gets all query parts.
* Gets all query parts.
*
*
* @return
mixed[]
* @return
array<string, mixed>
*/
*/
public
function
getQueryParts
()
public
function
getQueryParts
()
:
array
{
{
return
$this
->
sqlParts
;
return
$this
->
sqlParts
;
}
}
...
@@ -1086,11 +1076,11 @@ class QueryBuilder
...
@@ -1086,11 +1076,11 @@ class QueryBuilder
/**
/**
* Resets SQL parts.
* Resets SQL parts.
*
*
* @param
string[]
|null $queryPartNames
* @param
array<int, string>
|null $queryPartNames
*
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
resetQueryParts
(
$queryPartNames
=
null
)
public
function
resetQueryParts
(
?
array
$queryPartNames
=
null
)
:
self
{
{
if
(
$queryPartNames
===
null
)
{
if
(
$queryPartNames
===
null
)
{
$queryPartNames
=
array_keys
(
$this
->
sqlParts
);
$queryPartNames
=
array_keys
(
$this
->
sqlParts
);
...
@@ -1106,11 +1096,9 @@ class QueryBuilder
...
@@ -1106,11 +1096,9 @@ class QueryBuilder
/**
/**
* Resets a single SQL part.
* Resets a single SQL part.
*
*
* @param string $queryPartName
*
* @return $this This QueryBuilder instance.
* @return $this This QueryBuilder instance.
*/
*/
public
function
resetQueryPart
(
$queryPartName
)
public
function
resetQueryPart
(
string
$queryPartName
)
:
self
{
{
$this
->
sqlParts
[
$queryPartName
]
=
self
::
SQL_PARTS_DEFAULTS
[
$queryPartName
];
$this
->
sqlParts
[
$queryPartName
]
=
self
::
SQL_PARTS_DEFAULTS
[
$queryPartName
];
...
@@ -1120,11 +1108,9 @@ class QueryBuilder
...
@@ -1120,11 +1108,9 @@ class QueryBuilder
}
}
/**
/**
* @return string
*
* @throws QueryException
* @throws QueryException
*/
*/
private
function
getSQLForSelect
()
private
function
getSQLForSelect
()
:
string
{
{
$query
=
'SELECT '
.
(
$this
->
sqlParts
[
'distinct'
]
?
'DISTINCT '
:
''
)
.
$query
=
'SELECT '
.
(
$this
->
sqlParts
[
'distinct'
]
?
'DISTINCT '
:
''
)
.
implode
(
', '
,
$this
->
sqlParts
[
'select'
]);
implode
(
', '
,
$this
->
sqlParts
[
'select'
]);
...
@@ -1147,9 +1133,9 @@ class QueryBuilder
...
@@ -1147,9 +1133,9 @@ class QueryBuilder
}
}
/**
/**
* @return
string[]
* @return
array<string, string>
*/
*/
private
function
getFromClauses
()
private
function
getFromClauses
()
:
array
{
{
$fromClauses
=
[];
$fromClauses
=
[];
$knownAliases
=
[];
$knownAliases
=
[];
...
@@ -1158,9 +1144,13 @@ class QueryBuilder
...
@@ -1158,9 +1144,13 @@ class QueryBuilder
foreach
(
$this
->
sqlParts
[
'from'
]
as
$from
)
{
foreach
(
$this
->
sqlParts
[
'from'
]
as
$from
)
{
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
])
{
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
])
{
$tableSql
=
$from
[
'table'
];
$tableSql
=
$from
[
'table'
];
/** @var string $tableReference */
$tableReference
=
$from
[
'table'
];
$tableReference
=
$from
[
'table'
];
}
else
{
}
else
{
$tableSql
=
$from
[
'table'
]
.
' '
.
$from
[
'alias'
];
$tableSql
=
$from
[
'table'
]
.
' '
.
$from
[
'alias'
];
/** @var string $tableReference */
$tableReference
=
$from
[
'alias'
];
$tableReference
=
$from
[
'alias'
];
}
}
...
@@ -1175,11 +1165,11 @@ class QueryBuilder
...
@@ -1175,11 +1165,11 @@ class QueryBuilder
}
}
/**
/**
* @param
string[]
$knownAliases
* @param
array<string, true>
$knownAliases
*
*
* @throws QueryException
* @throws QueryException
*/
*/
private
function
verifyAllAliasesAreKnown
(
array
$knownAliases
)
private
function
verifyAllAliasesAreKnown
(
array
$knownAliases
)
:
void
{
{
foreach
(
$this
->
sqlParts
[
'join'
]
as
$fromAlias
=>
$joins
)
{
foreach
(
$this
->
sqlParts
[
'join'
]
as
$fromAlias
=>
$joins
)
{
if
(
!
isset
(
$knownAliases
[
$fromAlias
]))
{
if
(
!
isset
(
$knownAliases
[
$fromAlias
]))
{
...
@@ -1188,20 +1178,15 @@ class QueryBuilder
...
@@ -1188,20 +1178,15 @@ class QueryBuilder
}
}
}
}
/**
private
function
isLimitQuery
()
:
bool
* @return bool
*/
private
function
isLimitQuery
()
{
{
return
$this
->
maxResults
!==
null
||
$this
->
firstResult
!==
null
;
return
$this
->
maxResults
!==
null
||
$this
->
firstResult
!==
0
;
}
}
/**
/**
* Converts this instance into an INSERT string in SQL.
* Converts this instance into an INSERT string in SQL.
*
* @return string
*/
*/
private
function
getSQLForInsert
()
private
function
getSQLForInsert
()
:
string
{
{
return
'INSERT INTO '
.
$this
->
sqlParts
[
'from'
][
'table'
]
.
return
'INSERT INTO '
.
$this
->
sqlParts
[
'from'
][
'table'
]
.
' ('
.
implode
(
', '
,
array_keys
(
$this
->
sqlParts
[
'values'
]))
.
')'
.
' ('
.
implode
(
', '
,
array_keys
(
$this
->
sqlParts
[
'values'
]))
.
')'
.
...
@@ -1210,10 +1195,8 @@ class QueryBuilder
...
@@ -1210,10 +1195,8 @@ class QueryBuilder
/**
/**
* Converts this instance into an UPDATE string in SQL.
* Converts this instance into an UPDATE string in SQL.
*
* @return string
*/
*/
private
function
getSQLForUpdate
()
private
function
getSQLForUpdate
()
:
string
{
{
$from
=
$this
->
sqlParts
[
'from'
];
$from
=
$this
->
sqlParts
[
'from'
];
...
@@ -1230,10 +1213,8 @@ class QueryBuilder
...
@@ -1230,10 +1213,8 @@ class QueryBuilder
/**
/**
* Converts this instance into a DELETE string in SQL.
* Converts this instance into a DELETE string in SQL.
*
* @return string
*/
*/
private
function
getSQLForDelete
()
private
function
getSQLForDelete
()
:
string
{
{
$from
=
$this
->
sqlParts
[
'from'
];
$from
=
$this
->
sqlParts
[
'from'
];
...
@@ -1252,7 +1233,7 @@ class QueryBuilder
...
@@ -1252,7 +1233,7 @@ class QueryBuilder
*
*
* @return string The string representation of this QueryBuilder.
* @return string The string representation of this QueryBuilder.
*/
*/
public
function
__toString
()
public
function
__toString
()
:
string
{
{
return
$this
->
getSQL
();
return
$this
->
getSQL
();
}
}
...
@@ -1285,7 +1266,7 @@ class QueryBuilder
...
@@ -1285,7 +1266,7 @@ class QueryBuilder
*
*
* @return string the placeholder name used.
* @return string the placeholder name used.
*/
*/
public
function
createNamedParameter
(
$value
,
$type
=
ParameterType
::
STRING
,
$placeHolder
=
null
)
public
function
createNamedParameter
(
$value
,
$type
=
ParameterType
::
STRING
,
?
string
$placeHolder
=
null
)
:
string
{
{
if
(
$placeHolder
===
null
)
{
if
(
$placeHolder
===
null
)
{
$this
->
boundCounter
++
;
$this
->
boundCounter
++
;
...
@@ -1314,11 +1295,8 @@ class QueryBuilder
...
@@ -1314,11 +1295,8 @@ class QueryBuilder
* </code>
* </code>
*
*
* @param mixed $value
* @param mixed $value
* @param int $type
*
* @return string
*/
*/
public
function
createPositionalParameter
(
$value
,
$type
=
ParameterType
::
STRING
)
public
function
createPositionalParameter
(
$value
,
int
$type
=
ParameterType
::
STRING
)
:
string
{
{
$this
->
boundCounter
++
;
$this
->
boundCounter
++
;
$this
->
setParameter
(
$this
->
boundCounter
,
$value
,
$type
);
$this
->
setParameter
(
$this
->
boundCounter
,
$value
,
$type
);
...
@@ -1327,14 +1305,11 @@ class QueryBuilder
...
@@ -1327,14 +1305,11 @@ class QueryBuilder
}
}
/**
/**
* @param string $fromAlias
* @param array<string, true> $knownAliases
* @param string[] $knownAliases
*
* @return string
*
*
* @throws QueryException
* @throws QueryException
*/
*/
private
function
getSQLForJoins
(
$fromAlias
,
array
&
$knownAliases
)
private
function
getSQLForJoins
(
string
$fromAlias
,
array
&
$knownAliases
)
:
string
{
{
$sql
=
''
;
$sql
=
''
;
...
@@ -1359,8 +1334,6 @@ class QueryBuilder
...
@@ -1359,8 +1334,6 @@ class QueryBuilder
/**
/**
* Deep clone of all expression objects in the SQL parts.
* Deep clone of all expression objects in the SQL parts.
*
* @return void
*/
*/
public
function
__clone
()
public
function
__clone
()
{
{
...
...
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