Skip to content

Commit b2b8be6

Browse files
MAGETWO-70138: Fixed coding standard violations in the Framework\Model namespace #9361
2 parents c6c2f7e + b0c11b0 commit b2b8be6

File tree

5 files changed

+68
-60
lines changed

5 files changed

+68
-60
lines changed

lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php

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

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\Model\ResourceModel\Db\Collection;
10-
use Magento\Framework\App\ResourceConnection\SourceProviderInterface;
8+
9+
use \Magento\Framework\App\ResourceConnection\SourceProviderInterface;
10+
use \Magento\Framework\Data\Collection\AbstractDb;
1111

1212
/**
1313
* Abstract Resource Collection
1414
*
1515
* @api
1616
* @SuppressWarnings(PHPMD.NumberOfChildren)
1717
*/
18-
abstract class AbstractCollection extends \Magento\Framework\Data\Collection\AbstractDb
19-
implements SourceProviderInterface
18+
abstract class AbstractCollection extends AbstractDb implements SourceProviderInterface
2019
{
2120
/**
2221
* Model name
@@ -233,12 +232,11 @@ protected function _initSelectFields()
233232
$column = $field;
234233
}
235234

236-
if ($alias !== null && in_array(
237-
$alias,
238-
$columnsToSelect
239-
) ||
235+
if ($alias !== null &&
236+
in_array($alias, $columnsToSelect) ||
240237
// If field already joined from another table
241-
$alias === null && isset($alias, $columnsToSelect)
238+
$alias === null &&
239+
isset($alias, $columnsToSelect)
242240
) {
243241
continue;
244242
}
@@ -460,7 +458,9 @@ public function getResourceModelName()
460458
public function getResource()
461459
{
462460
if (empty($this->_resource)) {
463-
$this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->create($this->getResourceModelName());
461+
$this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->create(
462+
$this->getResourceModelName()
463+
);
464464
}
465465
return $this->_resource;
466466
}

lib/internal/Magento/Framework/Model/Test/Unit/AbstractExtensibleModelTest.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\Model\Test\Unit;
108

119
use Magento\Framework\Api\AttributeValue;

lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/Db/AbstractDbTest.php

Lines changed: 12 additions & 12 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\Model\Test\Unit\ResourceModel\Db;
108

119
use Magento\Framework\DB\Adapter\AdapterInterface;
@@ -139,7 +137,8 @@ public function testGetIdFieldname()
139137
{
140138
$data = 'MainTableName';
141139
$idFieldNameProperty = new \ReflectionProperty(
142-
AbstractDb::class, '_idFieldName'
140+
AbstractDb::class,
141+
'_idFieldName'
143142
);
144143
$idFieldNameProperty->setAccessible(true);
145144
$idFieldNameProperty->setValue($this->_model, $data);
@@ -171,8 +170,7 @@ public function testGetMainTable($tableName, $expectedResult)
171170
$this->_resourcesMock->expects($this->once())
172171
->method('getTableName')
173172
->with($expectedResult)
174-
->will($this->returnValue($expectedResult)
175-
);
173+
->will($this->returnValue($expectedResult));
176174
$this->assertEquals($expectedResult, $this->_model->getMainTable());
177175
}
178176

@@ -312,8 +310,7 @@ public function testDelete()
312310
);
313311
$this->_resourcesMock->expects($this->any())
314312
->method('getConnection')
315-
->will($this->returnValue($connectionInterfaceMock)
316-
);
313+
->will($this->returnValue($connectionInterfaceMock));
317314

318315
$abstractModelMock->expects($this->once())->method('getData')->willReturn(['data' => 'value']);
319316
$connectionMock = $this->getMock(AdapterInterface::class);
@@ -416,8 +413,7 @@ public function testGetDataChanged($getOriginData, $expected)
416413
$this->_resourcesMock->expects($this->once())
417414
->method('getTableName')
418415
->with('table')
419-
->will($this->returnValue('tableName')
420-
);
416+
->will($this->returnValue('tableName'));
421417
$abstractModelMock->expects($this->at(0))->method('getOrigData')->will($this->returnValue(true));
422418
$abstractModelMock->expects($this->at(1))->method('getOrigData')->will($this->returnValue($getOriginData));
423419
$connectionInterfaceMock->expects($this->any())->method('describeTable')->with('tableName')->will(
@@ -434,6 +430,9 @@ public function hasDataChangedDataProvider()
434430
];
435431
}
436432

433+
/**
434+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
435+
*/
437436
public function testPrepareDataForUpdate()
438437
{
439438
$connectionMock = $this->getMock(AdapterInterface::class, [], [], '', false);
@@ -473,8 +472,7 @@ public function testPrepareDataForUpdate()
473472
$data = 'tableName';
474473
$this->_resourcesMock->expects($this->any())
475474
->method('getConnection')
476-
->will($this->returnValue($connectionMock)
477-
);
475+
->will($this->returnValue($connectionMock));
478476
$this->_resourcesMock->expects($this->any())->method('getTableName')->with($data)->will(
479477
$this->returnValue('tableName')
480478
);
@@ -503,7 +501,9 @@ public function testPrepareDataForUpdate()
503501
$abstractModelMock->afterLoad();
504502
$this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
505503
$newData = ['value' => 'Test Value New'];
506-
$this->_model->expects($this->atLeastOnce())->method('_prepareDataForTable')->will($this->returnValue($newData));
504+
$this->_model->expects($this->atLeastOnce())
505+
->method('_prepareDataForTable')
506+
->will($this->returnValue($newData));
507507
$abstractModelMock->addData($newData);
508508
$this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
509509
$abstractModelMock->isObjectNew(false);

lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/Db/Collection/AbstractCollectionTest.php

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

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Framework\Model\Test\Unit\ResourceModel\Db\Collection;
108

119
use Magento\Framework\DB\Select;
12-
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1310
use Magento\Framework\DataObject as MagentoObject;
1411
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1512
use Magento\Framework\ObjectManagerInterface;
@@ -215,7 +212,11 @@ public function testGetSelect($idFieldNameRet, $getPartRet, $expected)
215212
->method('getPart')
216213
->will($this->returnValue($getPartRet));
217214

218-
$this->selectMock->expects($this->once())->method('setPart')->with(\Magento\Framework\DB\Select::COLUMNS, $expected);
215+
$this->selectMock
216+
->expects($this->once())
217+
->method('setPart')
218+
->with(\Magento\Framework\DB\Select::COLUMNS, $expected);
219+
219220
$this->assertTrue($this->uut->getSelect() instanceof Select);
220221
}
221222

@@ -410,34 +411,3 @@ public function testSave()
410411
$this->assertTrue($this->uut->save() instanceof Uut);
411412
}
412413
}
413-
414-
/**
415-
* Pattern type: Public Morozov
416-
*/
417-
class Uut extends AbstractCollection
418-
{
419-
public function wereFieldsToSelectChanged()
420-
{
421-
return $this->_fieldsToSelectChanged;
422-
}
423-
424-
public function getFieldsToSelect()
425-
{
426-
return $this->_fieldsToSelect;
427-
}
428-
429-
public function setFieldsToSelect(array $fields)
430-
{
431-
$this->_fieldsToSelect = $fields;
432-
}
433-
434-
public function setResource($resource)
435-
{
436-
$this->_resource = $resource;
437-
}
438-
439-
public function getJoinedTables()
440-
{
441-
return $this->_joinedTables;
442-
}
443-
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Model\Test\Unit\ResourceModel\Db\Collection;
8+
9+
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
10+
11+
/**
12+
* Pattern type: Public Morozov
13+
*/
14+
class Uut extends AbstractCollection
15+
{
16+
public function wereFieldsToSelectChanged()
17+
{
18+
return $this->_fieldsToSelectChanged;
19+
}
20+
21+
public function getFieldsToSelect()
22+
{
23+
return $this->_fieldsToSelect;
24+
}
25+
26+
public function setFieldsToSelect(array $fields)
27+
{
28+
$this->_fieldsToSelect = $fields;
29+
}
30+
31+
public function setResource($resource)
32+
{
33+
$this->_resource = $resource;
34+
}
35+
36+
public function getJoinedTables()
37+
{
38+
return $this->_joinedTables;
39+
}
40+
}

0 commit comments

Comments
 (0)