Skip to content

Commit c721bba

Browse files
committed
Fixed coding standard violations in the Framework\DB namespace, so that 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
1 parent c3040d3 commit c721bba

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@
2626
use Magento\Framework\Stdlib\DateTime;
2727
use Magento\Framework\Stdlib\StringUtils;
2828

29+
// @codingStandardsIgnoreStart
2930
/**
3031
* MySQL database adapter
3132
*
3233
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
3334
* @SuppressWarnings(PHPMD.TooManyFields)
3435
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
3536
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36-
* @codingStandardsIgnoreFile
3737
*/
3838
class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
3939
{
40+
// @codingStandardsIgnoreEnd
41+
4042
const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
4143
const DATETIME_FORMAT = 'Y-m-d H:i:s';
4244
const DATE_FORMAT = 'Y-m-d';
@@ -520,7 +522,9 @@ protected function _query($sql, $bind = [])
520522
$pdoException = null;
521523
if ($e instanceof \PDOException) {
522524
$pdoException = $e;
523-
} elseif (($e instanceof \Zend_Db_Statement_Exception) && ($e->getPrevious() instanceof \PDOException)) {
525+
} elseif (($e instanceof \Zend_Db_Statement_Exception)
526+
&& ($e->getPrevious() instanceof \PDOException)
527+
) {
524528
$pdoException = $e->getPrevious();
525529
}
526530

@@ -749,7 +753,6 @@ public function setQueryHook($hook)
749753
* @return array
750754
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
751755
* @SuppressWarnings(PHPMD.NPathComplexity)
752-
753756
* @deprecated
754757
*/
755758
protected function _splitMultiQuery($sql)
@@ -1640,9 +1643,7 @@ public function getColumnCreateByDescribe($columnData)
16401643
if ($columnData['PRIMARY'] === true) {
16411644
$options['primary'] = true;
16421645
}
1643-
if (!is_null($columnData['DEFAULT'])
1644-
&& $type != Table::TYPE_TEXT
1645-
) {
1646+
if ($columnData['DEFAULT'] !== null && $type != Table::TYPE_TEXT) {
16461647
$options['default'] = $this->quote($columnData['DEFAULT']);
16471648
}
16481649
if (strlen($columnData['SCALE']) > 0) {
@@ -1747,7 +1748,7 @@ public function modifyColumnByDdl($tableName, $columnName, $definition, $flushDa
17471748
{
17481749
$definition = array_change_key_case($definition, CASE_UPPER);
17491750
$definition['COLUMN_TYPE'] = $this->_getColumnTypeByDdl($definition);
1750-
if (array_key_exists('DEFAULT', $definition) && is_null($definition['DEFAULT'])) {
1751+
if (array_key_exists('DEFAULT', $definition) && $definition['DEFAULT'] === null) {
17511752
unset($definition['DEFAULT']);
17521753
}
17531754

@@ -2441,7 +2442,7 @@ protected function _getColumnDefinition($options, $ddlType = null)
24412442
} else {
24422443
$cDefault = false;
24432444
}
2444-
} elseif (is_null($cDefault) && $cNullable) {
2445+
} elseif ($cDefault === null && $cNullable) {
24452446
$cDefault = new \Zend_Db_Expr('NULL');
24462447
}
24472448

@@ -2937,7 +2938,7 @@ public function prepareColumnValue(array $column, $value)
29372938
}
29382939

29392940
// return null
2940-
if (is_null($value) && $column['NULLABLE']) {
2941+
if ($value === null && $column['NULLABLE']) {
29412942
return null;
29422943
}
29432944

@@ -3202,7 +3203,7 @@ public function getDatePartSql($date)
32023203
*/
32033204
public function getSubstringSql($stringExpression, $pos, $len = null)
32043205
{
3205-
if (is_null($len)) {
3206+
if ($len === null) {
32063207
return new \Zend_Db_Expr(sprintf('SUBSTRING(%s, %s)', $stringExpression, $pos));
32073208
}
32083209
return new \Zend_Db_Expr(sprintf('SUBSTRING(%s, %s, %s)', $stringExpression, $pos, $len));
@@ -3826,7 +3827,7 @@ public function __destruct()
38263827
*/
38273828
public function getTables($likeCondition = null)
38283829
{
3829-
$sql = is_null($likeCondition) ? 'SHOW TABLES' : sprintf("SHOW TABLES LIKE '%s'", $likeCondition);
3830+
$sql = ($likeCondition === null) ? 'SHOW TABLES' : sprintf("SHOW TABLES LIKE '%s'", $likeCondition);
38303831
$result = $this->query($sql);
38313832
$tables = [];
38323833
while ($row = $result->fetchColumn()) {

lib/internal/Magento/Framework/DB/MapperFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\DB;
108

119
/**

lib/internal/Magento/Framework/DB/QueryFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\DB;
108

119
/**

lib/internal/Magento/Framework/DB/Statement/Pdo/Mysql.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
/**
108
* Mysql DB Statement
119
*

lib/internal/Magento/Framework/DB/Test/Unit/AbstractMapperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\DB\Test\Unit;
108

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

249247
if (is_array($field)) {
250-
$resultCondition = '(' . implode(') ' . \Magento\Framework\DB\Select::SQL_OR
251-
. ' (', array_fill(0, count($field), $resultCondition)) . ')';
248+
$resultCondition = '(' . implode(
249+
') ' . \Magento\Framework\DB\Select::SQL_OR . ' (',
250+
array_fill(0, count($field), $resultCondition)
251+
) . ')';
252252
}
253253

254254
$this->selectMock->expects($this->once())

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\DB\Test\Unit\Adapter\Pdo;
108

119
use Magento\Framework\DB\Adapter\AdapterInterface;
@@ -56,11 +54,6 @@ protected function setUp()
5654
->disableOriginalConstructor()
5755
->getMock();
5856

59-
// StringUtils $string,
60-
// DateTime $dateTime,
61-
// LoggerInterface $logger,
62-
// SelectFactory $selectFactory,
63-
// array $config = []
6457
$this->_mockAdapter = $this->getMock(
6558
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
6659
['beginTransaction', 'getTransactionLevel'],
@@ -80,8 +73,8 @@ protected function setUp()
8073
);
8174

8275
$this->_mockAdapter->expects($this->any())
83-
->method('getTransactionLevel')
84-
->will($this->returnValue(1));
76+
->method('getTransactionLevel')
77+
->will($this->returnValue(1));
8578

8679
$this->_adapter = $this->getMock(
8780
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
@@ -471,7 +464,10 @@ public function testAddColumn($options, $expectedQuery)
471464
{
472465
$connectionMock = $this->getMock(
473466
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
474-
['tableColumnExists', '_getTableName', 'rawQuery', 'resetDdlCache', 'quote'], [], '', false
467+
['tableColumnExists', '_getTableName', 'rawQuery', 'resetDdlCache', 'quote'],
468+
[],
469+
'',
470+
false
475471
);
476472

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

0 commit comments

Comments
 (0)