Skip to content

Commit

Permalink
Fixed coding standard violations in the Framework\DB namespace, so th…
Browse files Browse the repository at this point in the history
…at it will be checked bij PHP CS and no longer be ignored while doing CI checks. Made the following changes:

- Removed @codingStandardsIgnoreFile from the head of the file
- Fixed indentation
- Changed is_null to strict === null compare
- Added codeignorestart and end around \Zend_Db_Adapter_Pdo, because it's not using namespace which is not allowed by PSR-2
- Removed commented out code from MysqlTest class
  • Loading branch information
dverkade committed Apr 21, 2017
1 parent c3040d3 commit c721bba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 31 deletions.
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

0 comments on commit c721bba

Please sign in to comment.