Skip to content

Commit 606715e

Browse files
committed
AC-3109 fixed logic affected by "RFC: Deprecate passing null"
1 parent fde5551 commit 606715e

File tree

13 files changed

+249
-188
lines changed

13 files changed

+249
-188
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Text.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @deprecated 100.2.0 in favour of UI component implementation
1515
* @since 100.0.2
1616
*/
17-
class Text extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
17+
class Text extends AbstractRenderer
1818
{
1919
/**
2020
* Format variables pattern
@@ -61,11 +61,11 @@ private function getSimpleValue(DataObject $row)
6161
*/
6262
private function getFormattedValue(DataObject $row)
6363
{
64-
$value = $this->getColumn()->getFormat() ?: null;
64+
$value = $this->getColumn()->getFormat() ?: '';
6565
if (true === $this->getColumn()->getTranslate()) {
6666
$value = __($value);
6767
}
68-
if (preg_match_all($this->_variablePattern, $value, $matches)) {
68+
if ($value && preg_match_all($this->_variablePattern, $value, $matches)) {
6969
foreach ($matches[0] as $index => $match) {
7070
$replacement = $row->getData($matches[1][$index]);
7171
$value = str_replace($match, $replacement, $value);

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

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
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;
912
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;
1021

1122
/**
1223
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
@@ -16,12 +27,12 @@
1627
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1728
* @since 100.0.2
1829
*/
19-
class Export extends \Magento\Backend\Block\Widget implements \Magento\Backend\Block\Widget\Grid\ExportInterface
30+
class Export extends Widget implements ExportInterface
2031
{
2132
/**
2233
* Grid export types
2334
*
24-
* @var \Magento\Framework\DataObject[]
35+
* @var DataObject[]
2536
*/
2637
protected $_exportTypes = [];
2738

@@ -40,12 +51,12 @@ class Export extends \Magento\Backend\Block\Widget implements \Magento\Backend\B
4051
protected $_template = "Magento_Backend::widget/grid/export.phtml";
4152

4253
/**
43-
* @var \Magento\Framework\Data\CollectionFactory
54+
* @var CollectionFactory
4455
*/
4556
protected $_collectionFactory;
4657

4758
/**
48-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
59+
* @var WriteInterface
4960
*/
5061
protected $_directory;
5162

@@ -57,13 +68,13 @@ class Export extends \Magento\Backend\Block\Widget implements \Magento\Backend\B
5768
protected $_path = 'export';
5869

5970
/**
60-
* @param \Magento\Backend\Block\Template\Context $context
61-
* @param \Magento\Framework\Data\CollectionFactory $collectionFactory
71+
* @param Context $context
72+
* @param CollectionFactory $collectionFactory
6273
* @param array $data
6374
*/
6475
public function __construct(
65-
\Magento\Backend\Block\Template\Context $context,
66-
\Magento\Framework\Data\CollectionFactory $collectionFactory,
76+
Context $context,
77+
CollectionFactory $collectionFactory,
6778
array $data = []
6879
) {
6980
$this->_collectionFactory = $collectionFactory;
@@ -74,15 +85,15 @@ public function __construct(
7485
* Internal constructor, that is called from real constructor
7586
*
7687
* @return void
77-
* @throws \Magento\Framework\Exception\LocalizedException
88+
* @throws LocalizedException
7889
*/
7990
protected function _construct()
8091
{
8192
parent::_construct();
8293
if ($this->hasData('exportTypes')) {
8394
foreach ($this->getData('exportTypes') as $type) {
8495
if (!isset($type['urlPath']) || !isset($type['label'])) {
85-
throw new \Magento\Framework\Exception\LocalizedException(
96+
throw new LocalizedException(
8697
__('Invalid export type supplied for grid export block')
8798
);
8899
}
@@ -95,7 +106,7 @@ protected function _construct()
95106
/**
96107
* Retrieve grid columns
97108
*
98-
* @return \Magento\Backend\Block\Widget\Grid\Column[]
109+
* @return Column[]
99110
*/
100111
protected function _getColumns()
101112
{
@@ -105,7 +116,7 @@ protected function _getColumns()
105116
/**
106117
* Retrieve totals
107118
*
108-
* @return \Magento\Framework\DataObject
119+
* @return DataObject
109120
*/
110121
protected function _getTotals()
111122
{
@@ -126,7 +137,7 @@ public function getCountTotals()
126137
/**
127138
* Get collection object
128139
*
129-
* @return \Magento\Framework\Data\Collection
140+
* @return Collection
130141
*/
131142
protected function _getCollection()
132143
{
@@ -136,7 +147,7 @@ protected function _getCollection()
136147
/**
137148
* Retrieve grid export types
138149
*
139-
* @return \Magento\Framework\DataObject[]|false
150+
* @return DataObject[]|false
140151
*/
141152
public function getExportTypes()
142153
{
@@ -157,13 +168,14 @@ public function getId()
157168
* Prepare export button
158169
*
159170
* @return $this
171+
* @throws LocalizedException
160172
*/
161173
protected function _prepareLayout()
162174
{
163175
$this->setChild(
164176
'export_button',
165177
$this->getLayout()->createBlock(
166-
\Magento\Backend\Block\Widget\Button::class
178+
Button::class
167179
)->setData(
168180
[
169181
'label' => __('Export'),
@@ -194,7 +206,7 @@ public function getExportButtonHtml()
194206
*/
195207
public function addExportType($url, $label)
196208
{
197-
$this->_exportTypes[] = new \Magento\Framework\DataObject(
209+
$this->_exportTypes[] = new DataObject(
198210
['url' => $this->getUrl($url, ['_current' => true]), 'label' => $label]
199211
);
200212
return $this;
@@ -205,6 +217,7 @@ public function addExportType($url, $label)
205217
*
206218
* @param array $fileData
207219
* @return string
220+
* @throws FileSystemException
208221
*/
209222
protected function _getFileContainerContent(array $fileData)
210223
{
@@ -255,7 +268,7 @@ protected function _getExportTotals()
255268
*/
256269
public function _exportIterateCollection($callback, array $args)
257270
{
258-
/** @var $originalCollection \Magento\Framework\Data\Collection */
271+
/** @var $originalCollection Collection */
259272
$originalCollection = $this->getParentBlock()->getPreparedCollection();
260273
$count = null;
261274
$page = 1;
@@ -291,13 +304,14 @@ public function _exportIterateCollection($callback, array $args)
291304
/**
292305
* Write item data to csv export file
293306
*
294-
* @param \Magento\Framework\DataObject $item
295-
* @param \Magento\Framework\Filesystem\File\WriteInterface $stream
307+
* @param DataObject $item
308+
* @param FileWriteInterface $stream
296309
* @return void
310+
* @throws FileSystemException
297311
*/
298312
protected function _exportCsvItem(
299-
\Magento\Framework\DataObject $item,
300-
\Magento\Framework\Filesystem\File\WriteInterface $stream
313+
DataObject $item,
314+
FileWriteInterface $stream
301315
) {
302316
$row = [];
303317
foreach ($this->_getColumns() as $column) {
@@ -364,7 +378,7 @@ public function getCsv()
364378
$data[] = '"' . str_replace(
365379
['"', '\\'],
366380
['""', '\\\\'],
367-
$column->getRowFieldExport($item)
381+
$column->getRowFieldExport($item) ?: ''
368382
) . '"';
369383
}
370384
}
@@ -378,7 +392,7 @@ public function getCsv()
378392
$data[] = '"' . str_replace(
379393
['"', '\\'],
380394
['""', '\\\\'],
381-
$column->getRowFieldExport($this->_getTotals())
395+
$column->getRowFieldExport($this->_getTotals()) ?: ''
382396
) . '"';
383397
}
384398
}
@@ -418,10 +432,10 @@ public function getXml()
418432
/**
419433
* Get a row data of the particular columns
420434
*
421-
* @param \Magento\Framework\DataObject $data
435+
* @param DataObject $data
422436
* @return string[]
423437
*/
424-
public function getRowRecord(\Magento\Framework\DataObject $data)
438+
public function getRowRecord(DataObject $data)
425439
{
426440
$row = [];
427441
foreach ($this->_getColumns() as $column) {
@@ -444,7 +458,7 @@ public function getExcelFile($sheetName = '')
444458
{
445459
$collection = $this->_getPreparedCollection();
446460

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

449463
$name = hash('sha256', microtime());
450464
$file = $this->_path . '/' . $name . '.xml';
@@ -507,30 +521,30 @@ public function getExcel()
507521
$data[] = $row;
508522
}
509523

510-
$convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($data));
524+
$convert = new Excel(new \ArrayIterator($data));
511525
return $convert->convert('single_sheet');
512526
}
513527

514528
/**
515529
* Reformat base collection into collection without sub-collection in items
516530
*
517-
* @param \Magento\Framework\Data\Collection $baseCollection
518-
* @return \Magento\Framework\Data\Collection
531+
* @param Collection $baseCollection
532+
* @return Collection
519533
*/
520-
protected function _getRowCollection(\Magento\Framework\Data\Collection $baseCollection = null)
534+
protected function _getRowCollection(Collection $baseCollection = null)
521535
{
522536
if (null === $baseCollection) {
523537
$baseCollection = $this->getParentBlock()->getPreparedCollection();
524538
}
525539
$collection = $this->_collectionFactory->create();
526540

527-
/** @var $item \Magento\Framework\DataObject */
541+
/** @var $item DataObject */
528542
foreach ($baseCollection as $item) {
529543
if ($item->getIsEmpty()) {
530544
continue;
531545
}
532546
if ($item->hasChildren() && count($item->getChildren()) > 0) {
533-
/** @var $subItem \Magento\Framework\DataObject */
547+
/** @var $subItem DataObject */
534548
foreach ($item->getChildren() as $subItem) {
535549
$tmpItem = clone $item;
536550
$tmpItem->unsChildren();
@@ -548,11 +562,11 @@ protected function _getRowCollection(\Magento\Framework\Data\Collection $baseCol
548562
/**
549563
* Return prepared collection as row collection with additional conditions
550564
*
551-
* @return \Magento\Framework\Data\Collection
565+
* @return Collection
552566
*/
553567
public function _getPreparedCollection()
554568
{
555-
/** @var $collection \Magento\Framework\Data\Collection */
569+
/** @var $collection Collection */
556570
$collection = $this->getParentBlock()->getPreparedCollection();
557571
$collection->setPageSize(0);
558572
$collection->load();

0 commit comments

Comments
 (0)