Scrutinizer fixes (#18685)

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/filters/AccessRule.php?selectedLabels%5B0%5D=2&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/helpers/BaseFileHelper.php?selectedLabels%5B0%5D=2&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Application.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Module.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/web/MultipartFormDataParser.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/web/Session.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Controller.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/MigrateController.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* Added vardocs, and small refactor

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/conditions/InConditionBuilder.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/Connection.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/mssql/QueryBuilder.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/log/Logger.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/BaseMigrateController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* Adding space between type

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/CacheController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/FixtureController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/MigrateController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0

* Update framework/console/controllers/CacheController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/CacheController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

* Update framework/console/controllers/FixtureController.php

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>

Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
This commit is contained in:
Bizley
2021-05-31 20:07:36 +02:00
committed by GitHub
parent 25a46828e9
commit 7966fe47e6
22 changed files with 95 additions and 83 deletions

View File

@ -1294,6 +1294,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public function link($name, $model, $extraColumns = [])
{
/* @var $relation ActiveQueryInterface|ActiveQuery */
$relation = $this->getRelation($name);
if ($relation->via !== null) {
@ -1330,16 +1331,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
$record->insert(false);
} else {
/* @var $viaTable string */
static::getDb()->createCommand()
->insert($viaTable, $columns)->execute();
static::getDb()->createCommand()->insert($viaTable, $columns)->execute();
}
} else {
$p1 = $model->isPrimaryKey(array_keys($relation->link));
$p2 = static::isPrimaryKey(array_values($relation->link));
if ($p1 && $p2) {
if ($this->getIsNewRecord() && $model->getIsNewRecord()) {
throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
} elseif ($this->getIsNewRecord()) {
if ($this->getIsNewRecord()) {
if ($model->getIsNewRecord()) {
throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
}
$this->bindModels(array_flip($relation->link), $this, $model);
} else {
$this->bindModels($relation->link, $model, $this);
@ -1492,6 +1493,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public function unlinkAll($name, $delete = false)
{
/* @var $relation ActiveQueryInterface|ActiveQuery */
$relation = $this->getRelation($name);
if ($relation->via !== null) {

View File

@ -694,20 +694,24 @@ class Connection extends Component
{
$pdoClass = $this->pdoClass;
if ($pdoClass === null) {
$pdoClass = 'PDO';
$driver = null;
if ($this->_driverName !== null) {
$driver = $this->_driverName;
} elseif (($pos = strpos($this->dsn, ':')) !== false) {
$driver = strtolower(substr($this->dsn, 0, $pos));
}
if (isset($driver)) {
if ($driver === 'mssql') {
switch ($driver) {
case 'mssql':
$pdoClass = 'yii\db\mssql\PDO';
} elseif ($driver === 'dblib') {
break;
case 'dblib':
$pdoClass = 'yii\db\mssql\DBLibPDO';
} elseif ($driver === 'sqlsrv') {
break;
case 'sqlsrv':
$pdoClass = 'yii\db\mssql\SqlsrvPDO';
}
break;
default:
$pdoClass = 'PDO';
}
}

View File

@ -54,18 +54,16 @@ class InConditionBuilder implements ExpressionBuilderInterface
if (is_array($column)) {
if (count($column) > 1) {
return $this->buildCompositeInCondition($operator, $column, $values, $params);
} else {
$column = reset($column);
}
$column = reset($column);
}
if ($column instanceof \Traversable) {
if (iterator_count($column) > 1) {
return $this->buildCompositeInCondition($operator, $column, $values, $params);
} else {
$column->rewind();
$column = $column->current();
}
$column->rewind();
$column = $column->current();
}
if (is_array($values)) {
@ -74,6 +72,8 @@ class InConditionBuilder implements ExpressionBuilderInterface
$rawValues = $this->getRawValuesFromTraversableObject($values);
}
$nullCondition = null;
$nullConditionOperator = null;
if (isset($rawValues) && in_array(null, $rawValues, true)) {
$nullCondition = $this->getNullCondition($operator, $column);
$nullConditionOperator = $operator === 'IN' ? 'OR' : 'AND';
@ -81,7 +81,7 @@ class InConditionBuilder implements ExpressionBuilderInterface
$sqlValues = $this->buildValues($expression, $values, $params);
if (empty($sqlValues)) {
if (!isset($nullCondition)) {
if ($nullCondition === null) {
return $operator === 'IN' ? '0=1' : '';
}
return $nullCondition;
@ -97,7 +97,9 @@ class InConditionBuilder implements ExpressionBuilderInterface
$sql = $column . $operator . reset($sqlValues);
}
return isset($nullCondition) ? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition) : $sql;
return $nullCondition !== null && $nullConditionOperator !== null
? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition)
: $sql;
}
/**

View File

@ -11,6 +11,7 @@ use yii\base\InvalidArgumentException;
use yii\base\NotSupportedException;
use yii\db\Constraint;
use yii\db\Expression;
use yii\db\TableSchema;
/**
* QueryBuilder is the query builder for MS SQL Server databases (version 2008 and above).
@ -483,10 +484,11 @@ class QueryBuilder extends \yii\db\QueryBuilder
$version2005orLater = version_compare($this->db->getSchema()->getServerVersion(), '9', '>=');
list($names, $placeholders, $values, $params) = $this->prepareInsertValues($table, $columns, $params);
$cols = [];
$columns = [];
if ($version2005orLater) {
/* @var $schema TableSchema */
$schema = $this->db->getTableSchema($table);
$cols = [];
$columns = [];
foreach ($schema->columns as $column) {
if ($column->isComputed) {
continue;

View File

@ -394,9 +394,9 @@ SQL;
}
if (!empty($matches[2])) {
$values = explode(',', $matches[2]);
$column->size = $column->precision = (int)$values[0];
$column->size = $column->precision = (int) $values[0];
if (isset($values[1])) {
$column->scale = (int)$values[1];
$column->scale = (int) $values[1];
}
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';

View File

@ -607,7 +607,7 @@ SQL;
$column->precision = $info['numeric_precision'];
$column->scale = $info['numeric_scale'];
$column->size = $info['size'] === null ? null : (int) $info['size'];
$column->dimension = (int)$info['dimension'];
$column->dimension = (int) $info['dimension'];
// pg_get_serial_sequence() doesn't track DEFAULT value change. GENERATED BY IDENTITY columns always have null default value
if (isset($column->defaultValue) && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) {
$column->sequenceName = preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue);