Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis improvements #4332

Merged
merged 4 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions lib/Doctrine/DBAL/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Cache;

use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Types\Type;

use function hash;
use function serialize;
Expand Down Expand Up @@ -68,10 +69,10 @@ public function getCacheKey()
/**
* Generates the real cache key from query, params, types and connection parameters.
*
* @param string $sql
* @param mixed[] $params
* @param int[]|string[] $types
* @param mixed[] $connectionParams
* @param string $sql
* @param array<int, mixed>|array<string, mixed> $params
* @param array<int, Type|int|string|null>|array<string, Type|int|string|null> $types
* @param array<string, mixed> $connectionParams
*
* @return string[]
*/
Expand Down
166 changes: 82 additions & 84 deletions lib/Doctrine/DBAL/Connection.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ public function rollBack()
/**
* {@inheritDoc}
*/
public function delete($table, array $identifier, array $types = [])
public function delete($table, array $criteria, array $types = [])
{
$this->ensureConnectedToPrimary();

return parent::delete($table, $identifier, $types);
return parent::delete($table, $criteria, $types);
}

/**
Expand All @@ -340,11 +340,11 @@ public function close()
/**
* {@inheritDoc}
*/
public function update($table, array $data, array $identifier, array $types = [])
public function update($table, array $data, array $criteria, array $types = [])
{
$this->ensureConnectedToPrimary();

return parent::update($table, $data, $identifier, $types);
return parent::update($table, $data, $criteria, $types);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Logging/SQLLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\DBAL\Logging;

use Doctrine\DBAL\Types\Type;

/**
* Interface for SQL loggers.
*/
Expand All @@ -10,9 +12,9 @@ interface SQLLogger
/**
* Logs a SQL statement somewhere.
*
* @param string $sql The SQL to be executed.
* @param mixed[]|null $params The SQL parameters.
* @param array<int|string|null> $types The SQL parameter types.
* @param string $sql SQL statement
* @param array<int, mixed>|array<string, mixed>|null $params Statement parameters
* @param array<int, Type|int|string|null>|array<string, Type|int|string|null>|null $types Parameter types
*
* @return void
*/
Expand Down
34 changes: 18 additions & 16 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Types\Type;

use function array_filter;
use function array_key_exists;
Expand Down Expand Up @@ -88,14 +89,14 @@ class QueryBuilder
/**
* The query parameters.
*
* @var mixed[]
* @var array<int, mixed>|array<string, mixed>
*/
private $params = [];

/**
* The parameter type map of this query.
*
* @var int[]|string[]
* @var array<int, int|string|Type|null>|array<string, int|string|Type|null>
*/
private $paramTypes = [];

Expand Down Expand Up @@ -263,9 +264,9 @@ public function getSQL()
* ->setParameter(':user_id', 1);
* </code>
*
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|int|null $type One of the {@link ParameterType} constants.
* @param int|string $key Parameter position or name
* @param mixed $value Parameter value
* @param int|string|Type|null $type One of the {@link ParameterType} constants or DBAL type
*
* @return $this This QueryBuilder instance.
*/
Expand Down Expand Up @@ -294,8 +295,8 @@ public function setParameter($key, $value, $type = null)
* ));
* </code>
*
* @param mixed[] $params The query parameters to set.
* @param int[]|string[] $types The query parameters types to set.
* @param array<int, mixed>|array<string, mixed> $params Parameters to set
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return $this This QueryBuilder instance.
*/
Expand All @@ -310,7 +311,7 @@ public function setParameters(array $params, array $types = [])
/**
* 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<int, mixed>|array<string, mixed> The currently defined query parameters
*/
public function getParameters()
{
Expand All @@ -332,7 +333,8 @@ public function getParameter($key)
/**
* 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<int, int|string|Type|null>|array<string, int|string|Type|null> The currently defined
* query parameter types
*/
public function getParameterTypes()
{
Expand All @@ -342,9 +344,9 @@ public function getParameterTypes()
/**
* 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 int|string $key The key of the bound parameter type
*
* @return mixed The value of the bound parameter type.
* @return int|string|Type|null The value of the bound parameter type
*/
public function getParameterType($key)
{
Expand Down Expand Up @@ -1291,9 +1293,9 @@ public function __toString()
*
* @link http://www.zetacomponents.org
*
* @param mixed $value
* @param mixed $type
* @param string $placeHolder The name to bind with. The string must start with a colon ':'.
* @param mixed $value
* @param int|string|Type|null $type
* @param string $placeHolder The name to bind with. The string must start with a colon ':'.
*
* @return string the placeholder name used.
*/
Expand Down Expand Up @@ -1326,8 +1328,8 @@ public function createNamedParameter($value, $type = ParameterType::STRING, $pla
* ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', ParameterType::STRING))
* </code>
*
* @param mixed $value
* @param int $type
* @param mixed $value
* @param int|string|Type|null $type
*
* @return string
*/
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\DBAL;

use Doctrine\DBAL\Types\Type;

use function array_fill;
use function array_fill_keys;
use function array_key_exists;
Expand Down Expand Up @@ -128,9 +130,9 @@ private static function collectPlaceholders(
/**
* For a positional query this method can rewrite the sql statement with regard to array parameters.
*
* @param string $query The SQL query to execute.
* @param mixed[] $params The parameters to bind to the query.
* @param array<string|int|null> $types The types the previous parameters are in.
* @param string $query SQL query
* @param mixed[] $params Query parameters
* @param array<int, Type|int|string|null>|array<string, Type|int|string|null> $types Parameter types
*
* @return mixed[]
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use function assert;
use function count;
use function implode;
use function is_array;
use function is_string;
use function trigger_error;

Expand Down Expand Up @@ -149,7 +150,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$conn = $this->getConnection($input);

$keywordLists = (array) $input->getOption('list');
$keywordLists = $input->getOption('list');

if (is_string($keywordLists)) {
$keywordLists = [$keywordLists];
} elseif (! is_array($keywordLists)) {
$keywordLists = [];
}

if (! $keywordLists) {
$keywordLists = [
'mysql',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BooleanType;

class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof DB2Platform;
}

public function testGetBooleanColumn(): void
{
$table = new Table('boolean_column_test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DrizzlePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BinaryType;

class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof DrizzlePlatform;
}

public function testListTableWithBinary(): void
{
$tableName = 'test_binary_table';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional\Schema;

use DateTime;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
Expand All @@ -15,6 +16,11 @@

class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof MySqlPlatform;
}

protected function setUp(): void
{
parent::setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BinaryType;
Expand All @@ -15,6 +17,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** @var bool */
private static $privilegesGranted = false;

protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof OraclePlatform;
}

protected function setUp(): void
{
parent::setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** @var PostgreSqlSchemaManager */
protected $schemaManager;

protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof PostgreSQL94Platform;
}

protected function tearDown(): void
{
parent::tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\View;

class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof SQLAnywherePlatform;
}

public function testCreateAndListViews(): void
{
$this->createTestTable('view_test_table');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Table;
Expand All @@ -12,9 +14,9 @@

class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function getPlatformName(): string
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return 'mssql';
return $platform instanceof SQLServer2012Platform;
}

public function testDropColumnConstraints(): void
Expand Down
Loading