Reworked all possible usages of the empty() construct and whitelisted the rest

parent f30a9a9a
......@@ -78,5 +78,15 @@ parameters:
-
message: '~^Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Doctrine\\DBAL\\Types\\Type and Doctrine\\DBAL\\Types\\Type will always evaluate to true\.$~'
path: %currentWorkingDirectory%/tests/Types/TypeRegistryTest.php
# https://github.com/phpstan/phpstan-strict-rules/issues/103
-
message: '~^Construct empty\(\) is not allowed. Use more strict comparison\.~'
paths:
- %currentWorkingDirectory%/src/Driver/*/*Connection.php
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
......@@ -23,6 +23,7 @@ use Exception;
use Throwable;
use function array_key_exists;
use function assert;
use function count;
use function implode;
use function is_int;
use function is_string;
......@@ -420,7 +421,7 @@ class Connection implements DriverConnection
try {
$this->connect();
} catch (Throwable $originalException) {
if (empty($this->params['dbname'])) {
if (! isset($this->params['dbname'])) {
throw $originalException;
}
......@@ -647,7 +648,7 @@ class Connection implements DriverConnection
*/
public function delete($tableExpression, array $identifier, array $types = [])
{
if (empty($identifier)) {
if (count($identifier) === 0) {
throw InvalidArgumentException::fromEmptyCriteria();
}
......@@ -753,7 +754,7 @@ class Connection implements DriverConnection
*/
public function insert($tableExpression, array $data, array $types = [])
{
if (empty($data)) {
if (count($data) === 0) {
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' () VALUES ()');
}
......
......@@ -45,11 +45,11 @@ final class EasyConnectString
*/
public static function fromConnectionParameters(array $params) : self
{
if (! empty($params['connectstring'])) {
if (isset($params['connectstring'])) {
return new self($params['connectstring']);
}
if (empty($params['host'])) {
if (! isset($params['host'])) {
return new self($params['dbname'] ?? '');
}
......@@ -58,7 +58,7 @@ final class EasyConnectString
if (isset($params['servicename']) || isset($params['dbname'])) {
$serviceKey = 'SID';
if (! empty($params['service'])) {
if (isset($params['service'])) {
$serviceKey = 'SERVICE_NAME';
}
......@@ -67,7 +67,7 @@ final class EasyConnectString
$connectData[$serviceKey] = $serviceName;
}
if (! empty($params['instancename'])) {
if (isset($params['instancename'])) {
$connectData['INSTANCE_NAME'] = $params['instancename'];
}
......
......@@ -55,7 +55,7 @@ class Driver extends AbstractSQLServerDriver
$dsn .= $params['host'];
}
if (isset($params['port']) && ! empty($params['port'])) {
if (isset($params['port'])) {
$dsn .= ',' . $params['port'];
}
......
......@@ -96,7 +96,7 @@ class CompositeExpression implements Countable
*/
public function add($part)
{
if (empty($part)) {
if ($part === null) {
return $this;
}
......
......@@ -10,6 +10,7 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use function array_key_exists;
use function array_keys;
use function array_unshift;
use function count;
use function func_get_args;
use function func_num_args;
use function implode;
......@@ -468,7 +469,7 @@ class QueryBuilder
{
$this->type = self::SELECT;
if (empty($select)) {
if ($select === null) {
return $this;
}
......@@ -518,7 +519,7 @@ class QueryBuilder
{
$this->type = self::SELECT;
if (empty($select)) {
if ($select === null) {
return $this;
}
......@@ -890,7 +891,7 @@ class QueryBuilder
*/
public function groupBy($groupBy/*, string ...$groupBys*/)
{
if (empty($groupBy)) {
if (is_array($groupBy) && count($groupBy) === 0) {
return $this;
}
......@@ -919,7 +920,7 @@ class QueryBuilder
*/
public function addGroupBy($groupBy/*, string ...$groupBys*/)
{
if (empty($groupBy)) {
if (is_array($groupBy) && count($groupBy) === 0) {
return $this;
}
......
......@@ -217,7 +217,7 @@ class Comparator
// See if column has changed properties in table 2.
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
if (empty($changedProperties)) {
if (count($changedProperties) === 0) {
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment