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

Fixed coding standard violations in the Framework\DB namespace #9353

Merged
merged 1 commit into from
Apr 22, 2017
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
23 changes: 12 additions & 11 deletions lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\Stdlib\StringUtils;

// @codingStandardsIgnoreStart
/**
* MySQL database adapter
*
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @codingStandardsIgnoreFile
*/
class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
{
// @codingStandardsIgnoreEnd

const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
const DATETIME_FORMAT = 'Y-m-d H:i:s';
const DATE_FORMAT = 'Y-m-d';
Expand Down Expand Up @@ -520,7 +522,9 @@ protected function _query($sql, $bind = [])
$pdoException = null;
if ($e instanceof \PDOException) {
$pdoException = $e;
} elseif (($e instanceof \Zend_Db_Statement_Exception) && ($e->getPrevious() instanceof \PDOException)) {
} elseif (($e instanceof \Zend_Db_Statement_Exception)
&& ($e->getPrevious() instanceof \PDOException)
) {
$pdoException = $e->getPrevious();
}

Expand Down Expand Up @@ -749,7 +753,6 @@ public function setQueryHook($hook)
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)

* @deprecated
*/
protected function _splitMultiQuery($sql)
Expand Down Expand Up @@ -1640,9 +1643,7 @@ public function getColumnCreateByDescribe($columnData)
if ($columnData['PRIMARY'] === true) {
$options['primary'] = true;
}
if (!is_null($columnData['DEFAULT'])
&& $type != Table::TYPE_TEXT
) {
if ($columnData['DEFAULT'] !== null && $type != Table::TYPE_TEXT) {
$options['default'] = $this->quote($columnData['DEFAULT']);
}
if (strlen($columnData['SCALE']) > 0) {
Expand Down Expand Up @@ -1747,7 +1748,7 @@ public function modifyColumnByDdl($tableName, $columnName, $definition, $flushDa
{
$definition = array_change_key_case($definition, CASE_UPPER);
$definition['COLUMN_TYPE'] = $this->_getColumnTypeByDdl($definition);
if (array_key_exists('DEFAULT', $definition) && is_null($definition['DEFAULT'])) {
if (array_key_exists('DEFAULT', $definition) && $definition['DEFAULT'] === null) {
unset($definition['DEFAULT']);
}

Expand Down Expand Up @@ -2441,7 +2442,7 @@ protected function _getColumnDefinition($options, $ddlType = null)
} else {
$cDefault = false;
}
} elseif (is_null($cDefault) && $cNullable) {
} elseif ($cDefault === null && $cNullable) {
$cDefault = new \Zend_Db_Expr('NULL');
}

Expand Down Expand Up @@ -2937,7 +2938,7 @@ public function prepareColumnValue(array $column, $value)
}

// return null
if (is_null($value) && $column['NULLABLE']) {
if ($value === null && $column['NULLABLE']) {
return null;
}

Expand Down Expand Up @@ -3202,7 +3203,7 @@ public function getDatePartSql($date)
*/
public function getSubstringSql($stringExpression, $pos, $len = null)
{
if (is_null($len)) {
if ($len === null) {
return new \Zend_Db_Expr(sprintf('SUBSTRING(%s, %s)', $stringExpression, $pos));
}
return new \Zend_Db_Expr(sprintf('SUBSTRING(%s, %s, %s)', $stringExpression, $pos, $len));
Expand Down Expand Up @@ -3826,7 +3827,7 @@ public function __destruct()
*/
public function getTables($likeCondition = null)
{
$sql = is_null($likeCondition) ? 'SHOW TABLES' : sprintf("SHOW TABLES LIKE '%s'", $likeCondition);
$sql = ($likeCondition === null) ? 'SHOW TABLES' : sprintf("SHOW TABLES LIKE '%s'", $likeCondition);
$result = $this->query($sql);
$tables = [];
while ($row = $result->fetchColumn()) {
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/Magento/Framework/DB/MapperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\DB;

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/Magento/Framework/DB/QueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\DB;

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/Magento/Framework/DB/Statement/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/**
* Mysql DB Statement
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\DB\Test\Unit;

use Magento\Framework\DB\Select;
Expand Down Expand Up @@ -247,8 +245,10 @@ public function testAddFieldToFilter($field, $condition)
->will($this->returnValue($resultCondition));

if (is_array($field)) {
$resultCondition = '(' . implode(') ' . \Magento\Framework\DB\Select::SQL_OR
. ' (', array_fill(0, count($field), $resultCondition)) . ')';
$resultCondition = '(' . implode(
') ' . \Magento\Framework\DB\Select::SQL_OR . ' (',
array_fill(0, count($field), $resultCondition)
) . ')';
}

$this->selectMock->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Framework\DB\Test\Unit\Adapter\Pdo;

use Magento\Framework\DB\Adapter\AdapterInterface;
Expand Down Expand Up @@ -56,11 +54,6 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();

// StringUtils $string,
// DateTime $dateTime,
// LoggerInterface $logger,
// SelectFactory $selectFactory,
// array $config = []
$this->_mockAdapter = $this->getMock(
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
['beginTransaction', 'getTransactionLevel'],
Expand All @@ -80,8 +73,8 @@ protected function setUp()
);

$this->_mockAdapter->expects($this->any())
->method('getTransactionLevel')
->will($this->returnValue(1));
->method('getTransactionLevel')
->will($this->returnValue(1));

$this->_adapter = $this->getMock(
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
Expand Down Expand Up @@ -471,7 +464,10 @@ public function testAddColumn($options, $expectedQuery)
{
$connectionMock = $this->getMock(
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
['tableColumnExists', '_getTableName', 'rawQuery', 'resetDdlCache', 'quote'], [], '', false
['tableColumnExists', '_getTableName', 'rawQuery', 'resetDdlCache', 'quote'],
[],
'',
false
);

$connectionMock->expects($this->any())->method('_getTableName')->will($this->returnArgument(0));
Expand Down