Skip to content

Commit ab27698

Browse files
committed
AC-3109 fixed static test
1 parent 606715e commit ab27698

File tree

8 files changed

+106
-131
lines changed

8 files changed

+106
-131
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Export.php

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,7 @@
66

77
namespace Magento\Backend\Block\Widget\Grid;
88

9-
use Magento\Backend\Block\Template\Context;
10-
use Magento\Backend\Block\Widget;
11-
use Magento\Backend\Block\Widget\Button;
129
use Magento\Framework\App\Filesystem\DirectoryList;
13-
use Magento\Framework\Convert\Excel;
14-
use Magento\Framework\Data\Collection;
15-
use Magento\Framework\Data\CollectionFactory;
16-
use Magento\Framework\DataObject;
17-
use Magento\Framework\Exception\FileSystemException;
18-
use Magento\Framework\Exception\LocalizedException;
19-
use Magento\Framework\Filesystem\Directory\WriteInterface;
20-
use Magento\Framework\Filesystem\File\WriteInterface as FileWriteInterface;
2110

2211
/**
2312
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
@@ -27,12 +16,12 @@
2716
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2817
* @since 100.0.2
2918
*/
30-
class Export extends Widget implements ExportInterface
19+
class Export extends \Magento\Backend\Block\Widget implements \Magento\Backend\Block\Widget\Grid\ExportInterface
3120
{
3221
/**
3322
* Grid export types
3423
*
35-
* @var DataObject[]
24+
* @var \Magento\Framework\DataObject[]
3625
*/
3726
protected $_exportTypes = [];
3827

@@ -51,12 +40,12 @@ class Export extends Widget implements ExportInterface
5140
protected $_template = "Magento_Backend::widget/grid/export.phtml";
5241

5342
/**
54-
* @var CollectionFactory
43+
* @var \Magento\Framework\Data\CollectionFactory
5544
*/
5645
protected $_collectionFactory;
5746

5847
/**
59-
* @var WriteInterface
48+
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
6049
*/
6150
protected $_directory;
6251

@@ -68,13 +57,13 @@ class Export extends Widget implements ExportInterface
6857
protected $_path = 'export';
6958

7059
/**
71-
* @param Context $context
72-
* @param CollectionFactory $collectionFactory
60+
* @param \Magento\Backend\Block\Template\Context $context
61+
* @param \Magento\Framework\Data\CollectionFactory $collectionFactory
7362
* @param array $data
7463
*/
7564
public function __construct(
76-
Context $context,
77-
CollectionFactory $collectionFactory,
65+
\Magento\Backend\Block\Template\Context $context,
66+
\Magento\Framework\Data\CollectionFactory $collectionFactory,
7867
array $data = []
7968
) {
8069
$this->_collectionFactory = $collectionFactory;
@@ -85,15 +74,15 @@ public function __construct(
8574
* Internal constructor, that is called from real constructor
8675
*
8776
* @return void
88-
* @throws LocalizedException
77+
* @throws \Magento\Framework\Exception\LocalizedException
8978
*/
9079
protected function _construct()
9180
{
9281
parent::_construct();
9382
if ($this->hasData('exportTypes')) {
9483
foreach ($this->getData('exportTypes') as $type) {
9584
if (!isset($type['urlPath']) || !isset($type['label'])) {
96-
throw new LocalizedException(
85+
throw new \Magento\Framework\Exception\LocalizedException(
9786
__('Invalid export type supplied for grid export block')
9887
);
9988
}
@@ -106,7 +95,7 @@ protected function _construct()
10695
/**
10796
* Retrieve grid columns
10897
*
109-
* @return Column[]
98+
* @return \Magento\Backend\Block\Widget\Grid\Column[]
11099
*/
111100
protected function _getColumns()
112101
{
@@ -116,7 +105,7 @@ protected function _getColumns()
116105
/**
117106
* Retrieve totals
118107
*
119-
* @return DataObject
108+
* @return \Magento\Framework\DataObject
120109
*/
121110
protected function _getTotals()
122111
{
@@ -137,7 +126,7 @@ public function getCountTotals()
137126
/**
138127
* Get collection object
139128
*
140-
* @return Collection
129+
* @return \Magento\Framework\Data\Collection
141130
*/
142131
protected function _getCollection()
143132
{
@@ -147,7 +136,7 @@ protected function _getCollection()
147136
/**
148137
* Retrieve grid export types
149138
*
150-
* @return DataObject[]|false
139+
* @return \Magento\Framework\DataObject[]|false
151140
*/
152141
public function getExportTypes()
153142
{
@@ -168,14 +157,13 @@ public function getId()
168157
* Prepare export button
169158
*
170159
* @return $this
171-
* @throws LocalizedException
172160
*/
173161
protected function _prepareLayout()
174162
{
175163
$this->setChild(
176164
'export_button',
177165
$this->getLayout()->createBlock(
178-
Button::class
166+
\Magento\Backend\Block\Widget\Button::class
179167
)->setData(
180168
[
181169
'label' => __('Export'),
@@ -206,7 +194,7 @@ public function getExportButtonHtml()
206194
*/
207195
public function addExportType($url, $label)
208196
{
209-
$this->_exportTypes[] = new DataObject(
197+
$this->_exportTypes[] = new \Magento\Framework\DataObject(
210198
['url' => $this->getUrl($url, ['_current' => true]), 'label' => $label]
211199
);
212200
return $this;
@@ -217,7 +205,6 @@ public function addExportType($url, $label)
217205
*
218206
* @param array $fileData
219207
* @return string
220-
* @throws FileSystemException
221208
*/
222209
protected function _getFileContainerContent(array $fileData)
223210
{
@@ -268,7 +255,7 @@ protected function _getExportTotals()
268255
*/
269256
public function _exportIterateCollection($callback, array $args)
270257
{
271-
/** @var $originalCollection Collection */
258+
/** @var $originalCollection \Magento\Framework\Data\Collection */
272259
$originalCollection = $this->getParentBlock()->getPreparedCollection();
273260
$count = null;
274261
$page = 1;
@@ -304,14 +291,13 @@ public function _exportIterateCollection($callback, array $args)
304291
/**
305292
* Write item data to csv export file
306293
*
307-
* @param DataObject $item
308-
* @param FileWriteInterface $stream
294+
* @param \Magento\Framework\DataObject $item
295+
* @param \Magento\Framework\Filesystem\File\WriteInterface $stream
309296
* @return void
310-
* @throws FileSystemException
311297
*/
312298
protected function _exportCsvItem(
313-
DataObject $item,
314-
FileWriteInterface $stream
299+
\Magento\Framework\DataObject $item,
300+
\Magento\Framework\Filesystem\File\WriteInterface $stream
315301
) {
316302
$row = [];
317303
foreach ($this->_getColumns() as $column) {
@@ -357,6 +343,7 @@ public function getCsvFile()
357343
* Retrieve Grid data as CSV
358344
*
359345
* @return string
346+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360347
*/
361348
public function getCsv()
362349
{
@@ -432,10 +419,10 @@ public function getXml()
432419
/**
433420
* Get a row data of the particular columns
434421
*
435-
* @param DataObject $data
422+
* @param \Magento\Framework\DataObject $data
436423
* @return string[]
437424
*/
438-
public function getRowRecord(DataObject $data)
425+
public function getRowRecord(\Magento\Framework\DataObject $data)
439426
{
440427
$row = [];
441428
foreach ($this->_getColumns() as $column) {
@@ -458,7 +445,7 @@ public function getExcelFile($sheetName = '')
458445
{
459446
$collection = $this->_getPreparedCollection();
460447

461-
$convert = new Excel($collection->getIterator(), [$this, 'getRowRecord']);
448+
$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);
462449

463450
$name = hash('sha256', microtime());
464451
$file = $this->_path . '/' . $name . '.xml';
@@ -521,30 +508,30 @@ public function getExcel()
521508
$data[] = $row;
522509
}
523510

524-
$convert = new Excel(new \ArrayIterator($data));
511+
$convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($data));
525512
return $convert->convert('single_sheet');
526513
}
527514

528515
/**
529516
* Reformat base collection into collection without sub-collection in items
530517
*
531-
* @param Collection $baseCollection
532-
* @return Collection
518+
* @param \Magento\Framework\Data\Collection $baseCollection
519+
* @return \Magento\Framework\Data\Collection
533520
*/
534-
protected function _getRowCollection(Collection $baseCollection = null)
521+
protected function _getRowCollection(\Magento\Framework\Data\Collection $baseCollection = null)
535522
{
536523
if (null === $baseCollection) {
537524
$baseCollection = $this->getParentBlock()->getPreparedCollection();
538525
}
539526
$collection = $this->_collectionFactory->create();
540527

541-
/** @var $item DataObject */
528+
/** @var $item \Magento\Framework\DataObject */
542529
foreach ($baseCollection as $item) {
543530
if ($item->getIsEmpty()) {
544531
continue;
545532
}
546533
if ($item->hasChildren() && count($item->getChildren()) > 0) {
547-
/** @var $subItem DataObject */
534+
/** @var $subItem \Magento\Framework\DataObject */
548535
foreach ($item->getChildren() as $subItem) {
549536
$tmpItem = clone $item;
550537
$tmpItem->unsChildren();
@@ -562,11 +549,11 @@ protected function _getRowCollection(Collection $baseCollection = null)
562549
/**
563550
* Return prepared collection as row collection with additional conditions
564551
*
565-
* @return Collection
552+
* @return \Magento\Framework\Data\Collection
566553
*/
567554
public function _getPreparedCollection()
568555
{
569-
/** @var $collection Collection */
556+
/** @var $collection \Magento\Framework\Data\Collection */
570557
$collection = $this->getParentBlock()->getPreparedCollection();
571558
$collection->setPageSize(0);
572559
$collection->load();

0 commit comments

Comments
 (0)