Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

3.0.0 sql type hints #373

Open
wants to merge 49 commits into
base: 3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
91d68c4
Added some typehints
guidofaecke Mar 14, 2019
42e8770
Added access modifiers for class constants
arueckauer Mar 16, 2019
ae5c556
Updated return type declarations
arueckauer Mar 16, 2019
4a084fa
Use ::class instead
arueckauer Mar 16, 2019
bda3610
Use short list syntax
arueckauer Mar 16, 2019
fdc6130
Use origin function
arueckauer Mar 16, 2019
4524104
Removed misusage of array_push()
arueckauer Mar 16, 2019
a55d7fd
Removed assignments where written value is same as default one
arueckauer Mar 16, 2019
18986fc
Removed superfluous null assignments on class property initialization
arueckauer Mar 16, 2019
e4868fa
Write single-line comments with @var as one-liners
arueckauer Mar 16, 2019
b9ce140
Updated file header comment, added strict_types declaration
arueckauer Mar 16, 2019
6ebaf9d
Removed empty comment lines
arueckauer Mar 16, 2019
4ec4ee5
Updated argument and return type declarations, removed method comment…
arueckauer Mar 16, 2019
788d1bc
Treat string class properties as not nullable where possible
arueckauer Mar 16, 2019
f97e6f7
Comment tags @param, @throws and @return should not be aligned or con…
arueckauer Mar 16, 2019
9565442
Revert short list syntax where incompatible
arueckauer Mar 16, 2019
9af735e
Ignore IDE files
arueckauer Mar 16, 2019
e057005
Ensure declarations are compatible with super, noted where type hints…
arueckauer Mar 16, 2019
2c385f7
Updated return type in DocBlock
arueckauer Mar 16, 2019
c2ab9c3
Fixed case mismatch
arueckauer Mar 16, 2019
0f8f3f4
Use self class referencing
arueckauer Mar 16, 2019
f4feef2
Use single quotes
arueckauer Mar 16, 2019
6000d50
Remove unnecessary parentheses
arueckauer Mar 16, 2019
5866062
Remove unnecessary type casting, as the argument is of needed type
arueckauer Mar 16, 2019
31c14f6
Place namespace definition on its own line
arueckauer Mar 16, 2019
5f115d1
Use compact()
arueckauer Mar 16, 2019
a60c5c2
Converted elseif to if-branch (clearer intention, lower complexity nu…
arueckauer Mar 16, 2019
402e21b
Define one parameter per line in multi-line function declarations
arueckauer Mar 16, 2019
552623f
Removed unused imports
arueckauer Mar 16, 2019
a5d9333
Fixed typo
arueckauer Mar 16, 2019
471da0c
There must be exactly one space after a type cast
arueckauer Mar 16, 2019
636167e
Nullable and optional arguments, which are marked as = null, must hav…
arueckauer Mar 16, 2019
73c4a59
Removed comments which do not add valuable information
arueckauer Mar 16, 2019
5bb0ad8
Revert short list syntax where incompatible
arueckauer Mar 16, 2019
aca883d
Removed duplicate blank lines
arueckauer Mar 16, 2019
1c0ddf4
Merge pull request #1 from guidofaecke/3.0.0_SQL_typeHints
guidofaecke Mar 16, 2019
f94abb7
Resolving merge conflict
guidofaecke Mar 17, 2019
25d7ee3
Merge remote-tracking branch 'origin/3.0.0' into 3.0.0_SQL_typeHints
guidofaecke Mar 17, 2019
677d31a
Resolving merge conflict
guidofaecke Mar 17, 2019
5901b66
Merge branch '3.0.0' into 3.0.0_SQL_typeHints
guidofaecke Mar 17, 2019
417ca86
removed IDE/OS specifics
guidofaecke Mar 17, 2019
16dbb40
fixed typehint
guidofaecke Mar 17, 2019
da8b22b
added parenthesis
guidofaecke Mar 17, 2019
311ad6c
changed self to $this
guidofaecke Mar 17, 2019
110f777
fixed column constructor
guidofaecke Mar 17, 2019
65409db
alignment and use function statements
guidofaecke Mar 17, 2019
ac29abe
comparator
guidofaecke Mar 17, 2019
f748754
parenthesis fixed
guidofaecke Mar 17, 2019
ba08bf4
return fix
guidofaecke Mar 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have any IDE/OS specific files/directories here. Please revert and add it to your global .gitignore.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

/clover.xml
/coveralls-upload.json
/docs/html/
Expand Down
8 changes: 8 additions & 0 deletions 3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Changed `setDriver(DriverInterface $driver)` for all the following platforms:
- Zend\Db\Adapter\Platform\Postgresql
- Zend\Db\Adapter\Platform\Sqlite
- Zend\Db\Adapter\Platform\SqlServer

- Zend\Db\Sql\Platform\PlatformDecoratorInterface

`setSubject()` cannot be type hinted, since implementations use various types

- Zend\Db\Sql\AbstractSql

`Zend\Db\Sql\Select::resolveTable()` returns an array where as its parent returns a string
44 changes: 26 additions & 18 deletions src/Sql/AbstractExpression.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2005-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace Zend\Db\Sql;

use Zend\Db\Sql\Exception\InvalidArgumentException;
use function current;
use function get_class;
use function gettype;
use function implode;
use function in_array;
use function is_array;
use function is_int;
use function is_object;
use function is_scalar;
use function key;

abstract class AbstractExpression implements ExpressionInterface
{
/**
* @var string[]
*/
/** @var string[] */
protected $allowedTypes = [
self::TYPE_IDENTIFIER,
self::TYPE_LITERAL,
Expand All @@ -26,12 +36,11 @@ abstract class AbstractExpression implements ExpressionInterface
*
* @param mixed $argument
* @param string $defaultType
*
* @return array
*
* @throws Exception\InvalidArgumentException
*/
protected function normalizeArgument($argument, $defaultType = self::TYPE_VALUE)
protected function normalizeArgument($argument, string $defaultType = self::TYPE_VALUE) : array
{
if ($argument instanceof ExpressionInterface || $argument instanceof SqlInterface) {
return $this->buildNormalizedArgument($argument, self::TYPE_VALUE);
Expand All @@ -50,36 +59,35 @@ protected function normalizeArgument($argument, $defaultType = self::TYPE_VALUE)

$key = key($argument);

if (is_integer($key) && ! in_array($value, $this->allowedTypes)) {
if (is_int($key) && ! in_array($value, $this->allowedTypes)) {
return $this->buildNormalizedArgument($value, $defaultType);
}

return $this->buildNormalizedArgument($key, $value);
}

throw new Exception\InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'$argument should be %s or %s or %s or %s or %s, "%s" given',
'null',
'scalar',
'array',
'Zend\Db\Sql\ExpressionInterface',
'Zend\Db\Sql\SqlInterface',
ExpressionInterface::class,
SqlInterface::class,
is_object($argument) ? get_class($argument) : gettype($argument)
));
}

/**
* @param mixed $argument
* @param string $argumentType
*
* @return array
* @return mixed[]
*
* @throws Exception\InvalidArgumentException
*/
private function buildNormalizedArgument($argument, $argumentType)
private function buildNormalizedArgument($argument, string $argumentType) : array
{
if (! in_array($argumentType, $this->allowedTypes)) {
throw new Exception\InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Argument type should be in array(%s)',
implode(',', $this->allowedTypes)
));
Expand Down
23 changes: 10 additions & 13 deletions src/Sql/AbstractPreparableSql.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2005-2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace Zend\Db\Sql;

use Zend\Db\Adapter\StatementContainerInterface;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\StatementContainerInterface;

abstract class AbstractPreparableSql extends AbstractSql implements PreparableSqlInterface
{
/**
* {@inheritDoc}
*
* @return StatementContainerInterface
*/
public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
{
public function prepareStatement(
AdapterInterface $adapter,
StatementContainerInterface $statementContainer
) : StatementContainerInterface {
$parameterContainer = $statementContainer->getParameterContainer();

if (! $parameterContainer instanceof ParameterContainer) {
Expand Down
Loading