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

parent f30a9a9a
...@@ -78,5 +78,15 @@ parameters: ...@@ -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\.$~' 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 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: includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon
...@@ -23,6 +23,7 @@ use Exception; ...@@ -23,6 +23,7 @@ use Exception;
use Throwable; use Throwable;
use function array_key_exists; use function array_key_exists;
use function assert; use function assert;
use function count;
use function implode; use function implode;
use function is_int; use function is_int;
use function is_string; use function is_string;
...@@ -420,7 +421,7 @@ class Connection implements DriverConnection ...@@ -420,7 +421,7 @@ class Connection implements DriverConnection
try { try {
$this->connect(); $this->connect();
} catch (Throwable $originalException) { } catch (Throwable $originalException) {
if (empty($this->params['dbname'])) { if (! isset($this->params['dbname'])) {
throw $originalException; throw $originalException;
} }
...@@ -647,7 +648,7 @@ class Connection implements DriverConnection ...@@ -647,7 +648,7 @@ class Connection implements DriverConnection
*/ */
public function delete($tableExpression, array $identifier, array $types = []) public function delete($tableExpression, array $identifier, array $types = [])
{ {
if (empty($identifier)) { if (count($identifier) === 0) {
throw InvalidArgumentException::fromEmptyCriteria(); throw InvalidArgumentException::fromEmptyCriteria();
} }
...@@ -753,7 +754,7 @@ class Connection implements DriverConnection ...@@ -753,7 +754,7 @@ class Connection implements DriverConnection
*/ */
public function insert($tableExpression, array $data, array $types = []) public function insert($tableExpression, array $data, array $types = [])
{ {
if (empty($data)) { if (count($data) === 0) {
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' () VALUES ()'); return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' () VALUES ()');
} }
......
...@@ -45,11 +45,11 @@ final class EasyConnectString ...@@ -45,11 +45,11 @@ final class EasyConnectString
*/ */
public static function fromConnectionParameters(array $params) : self public static function fromConnectionParameters(array $params) : self
{ {
if (! empty($params['connectstring'])) { if (isset($params['connectstring'])) {
return new self($params['connectstring']); return new self($params['connectstring']);
} }
if (empty($params['host'])) { if (! isset($params['host'])) {
return new self($params['dbname'] ?? ''); return new self($params['dbname'] ?? '');
} }
...@@ -58,7 +58,7 @@ final class EasyConnectString ...@@ -58,7 +58,7 @@ final class EasyConnectString
if (isset($params['servicename']) || isset($params['dbname'])) { if (isset($params['servicename']) || isset($params['dbname'])) {
$serviceKey = 'SID'; $serviceKey = 'SID';
if (! empty($params['service'])) { if (isset($params['service'])) {
$serviceKey = 'SERVICE_NAME'; $serviceKey = 'SERVICE_NAME';
} }
...@@ -67,7 +67,7 @@ final class EasyConnectString ...@@ -67,7 +67,7 @@ final class EasyConnectString
$connectData[$serviceKey] = $serviceName; $connectData[$serviceKey] = $serviceName;
} }
if (! empty($params['instancename'])) { if (isset($params['instancename'])) {
$connectData['INSTANCE_NAME'] = $params['instancename']; $connectData['INSTANCE_NAME'] = $params['instancename'];
} }
......
...@@ -55,7 +55,7 @@ class Driver extends AbstractSQLServerDriver ...@@ -55,7 +55,7 @@ class Driver extends AbstractSQLServerDriver
$dsn .= $params['host']; $dsn .= $params['host'];
} }
if (isset($params['port']) && ! empty($params['port'])) { if (isset($params['port'])) {
$dsn .= ',' . $params['port']; $dsn .= ',' . $params['port'];
} }
......
...@@ -96,7 +96,7 @@ class CompositeExpression implements Countable ...@@ -96,7 +96,7 @@ class CompositeExpression implements Countable
*/ */
public function add($part) public function add($part)
{ {
if (empty($part)) { if ($part === null) {
return $this; return $this;
} }
......
...@@ -10,6 +10,7 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder; ...@@ -10,6 +10,7 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use function array_key_exists; use function array_key_exists;
use function array_keys; use function array_keys;
use function array_unshift; use function array_unshift;
use function count;
use function func_get_args; use function func_get_args;
use function func_num_args; use function func_num_args;
use function implode; use function implode;
...@@ -468,7 +469,7 @@ class QueryBuilder ...@@ -468,7 +469,7 @@ class QueryBuilder
{ {
$this->type = self::SELECT; $this->type = self::SELECT;
if (empty($select)) { if ($select === null) {
return $this; return $this;
} }
...@@ -518,7 +519,7 @@ class QueryBuilder ...@@ -518,7 +519,7 @@ class QueryBuilder
{ {
$this->type = self::SELECT; $this->type = self::SELECT;
if (empty($select)) { if ($select === null) {
return $this; return $this;
} }
...@@ -890,7 +891,7 @@ class QueryBuilder ...@@ -890,7 +891,7 @@ class QueryBuilder
*/ */
public function groupBy($groupBy/*, string ...$groupBys*/) public function groupBy($groupBy/*, string ...$groupBys*/)
{ {
if (empty($groupBy)) { if (is_array($groupBy) && count($groupBy) === 0) {
return $this; return $this;
} }
...@@ -919,7 +920,7 @@ class QueryBuilder ...@@ -919,7 +920,7 @@ class QueryBuilder
*/ */
public function addGroupBy($groupBy/*, string ...$groupBys*/) public function addGroupBy($groupBy/*, string ...$groupBys*/)
{ {
if (empty($groupBy)) { if (is_array($groupBy) && count($groupBy) === 0) {
return $this; return $this;
} }
......
...@@ -217,7 +217,7 @@ class Comparator ...@@ -217,7 +217,7 @@ class Comparator
// See if column has changed properties in table 2. // See if column has changed properties in table 2.
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName)); $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
if (empty($changedProperties)) { if (count($changedProperties) === 0) {
continue; 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