Skip to content

Commit 7cbc883

Browse files
committed
Fixed code by recommendation
1 parent 58e8010 commit 7cbc883

File tree

10 files changed

+31
-53
lines changed

10 files changed

+31
-53
lines changed

dev/tests/integration/testsuite/Magento/Backend/Block/Widget/Grid/Massaction/AdditionalTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function testToHtml()
4141
$evaluatedValues
4242
);
4343

44+
$block->setNameInLayout('test_block_name');
4445
$html = $block->toHtml();
4546
$this->assertStringMatchesFormat(
4647
'%acustom_class absolute-advice%avalue="value1"%slabel 1%avalue="value2"%slabel 2%a',

dev/tests/integration/testsuite/Magento/Integration/Block/Adminhtml/Integration/TokensTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function testGetFormFields()
6868

6969
public function testToHtml()
7070
{
71+
$this->tokensBlock->setNameInLayout('test_block_name');
7172
$htmlContent = $this->tokensBlock->toHtml();
7273

7374
$this->assertStringContainsString('name="consumer_key"', $htmlContent);

dev/tests/integration/testsuite/Magento/Review/Block/Adminhtml/Edit/FormTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function testCustomerOnForm()
2424
->setWebsiteId(1)
2525
->loadByEmail('customer@example.com');
2626
$block = Bootstrap::getObjectManager()->create(Form::class);
27+
$block->setNameInLayout('test_block_name');
2728
/** @var Escaper $escaper */
2829
$escaper = Bootstrap::getObjectManager()->get(Escaper::class);
2930
$this->assertStringMatchesFormat(
@@ -49,6 +50,7 @@ public function testStoresOnForm(): void
4950
$registry = Bootstrap::getObjectManager()->get(Registry::class);
5051
$review = $registry->registry('review_data');
5152
$block = Bootstrap::getObjectManager()->create(Form::class);
53+
$block->setNameInLayout('test_block_name');
5254
foreach ($review->getStores() as $storeId) {
5355
$regex = sprintf('/input id="select_stores" (.*) value="%d" type="hidden"/', $storeId);
5456
$this->assertMatchesRegularExpression(

lib/internal/Magento/Framework/DB/Helper/AbstractHelper.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
/**
3+
* Abstract DB helper class
4+
*
35
* Copyright © Magento, Inc. All rights reserved.
46
* See COPYING.txt for license details.
57
*/
68
namespace Magento\Framework\DB\Helper;
79

8-
/**
9-
* Abstract DB helper class.
10-
*/
1110
abstract class AbstractHelper
1211
{
1312
/**
@@ -64,7 +63,7 @@ protected function getConnection()
6463
*/
6564
public function escapeLikeValue($value, $options = [])
6665
{
67-
$value = is_string($value) ? str_replace('\\', '\\\\', $value) : '';
66+
$value = str_replace('\\', '\\\\', $value);
6867

6968
$replaceFrom = [];
7069
$replaceTo = [];
@@ -101,7 +100,6 @@ public function escapeLikeValue($value, $options = [])
101100

102101
/**
103102
* Escapes, quotes and adds escape symbol to LIKE expression.
104-
*
105103
* For options and escaping see escapeLikeValue().
106104
*
107105
* @param string $value
@@ -114,7 +112,6 @@ abstract public function addLikeEscape($value, $options = []);
114112

115113
/**
116114
* Returns case insensitive LIKE construction.
117-
*
118115
* For options and escaping see escapeLikeValue().
119116
*
120117
* @param string $field

lib/internal/Magento/Framework/Filter/StripTags.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StripTags implements \Zend_Filter_Interface
2727

2828
/**
2929
* @param \Magento\Framework\Escaper $escaper
30-
* @param string|null $allowableTags
30+
* @param null $allowableTags
3131
* @param bool $escape
3232
*/
3333
public function __construct(\Magento\Framework\Escaper $escaper, $allowableTags = null, $escape = false)
@@ -45,8 +45,7 @@ public function __construct(\Magento\Framework\Escaper $escaper, $allowableTags
4545
*/
4646
public function filter($value)
4747
{
48-
$result = $value !== null ? strip_tags($value, $this->allowableTags) : '';
49-
48+
$result = strip_tags($value, $this->allowableTags);
5049
return $this->escape ? $this->escaper->escapeHtml($result, $this->allowableTags) : $result;
5150
}
5251
}

lib/internal/Magento/Framework/Image/Adapter/Gd2.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ private function fillBackgroundColor(&$imageResourceTo): void
294294
// fallback to default background color
295295
}
296296
}
297-
list($red, $green, $blue) = $this->_backgroundColor;
298-
$red = $red !== null ? $red : 0;
299-
$green = $green !== null ? $green : 0;
300-
$blue = $blue !== null ? $blue : 0;
297+
list($red, $green, $blue) = $this->_backgroundColor ?: [0, 0, 0];
301298
$color = imagecolorallocate($imageResourceTo, $red, $green, $blue);
302299

303300
if (!imagefill($imageResourceTo, 0, 0, $color)) {

lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class ImageMagick extends AbstractAdapter
1818
/**
1919
* The blur factor where > 1 is blurry, < 1 is sharp
2020
*/
21-
const BLUR_FACTOR = 0.7;
21+
public const BLUR_FACTOR = 0.7;
2222

2323
/**
2424
* Error messages
2525
*/
26-
const ERROR_WATERMARK_IMAGE_ABSENT = 'Watermark Image absent.';
26+
public const ERROR_WATERMARK_IMAGE_ABSENT = 'Watermark Image absent.';
2727

28-
const ERROR_WRONG_IMAGE = 'Image is not readable or file name is empty.';
28+
public const ERROR_WRONG_IMAGE = 'Image is not readable or file name is empty.';
2929

3030
/**
3131
* Options Container
@@ -90,9 +90,9 @@ public function backgroundColor($color = null)
9090
*/
9191
public function open($filename)
9292
{
93-
if (!file_exists($filename)) {
93+
if ($filename === null || !file_exists($filename)) {
9494
throw new FileSystemException(
95-
new Phrase('File "%1" does not exist.', [$this->_fileName])
95+
new Phrase('File "%1" does not exist.', [$filename])
9696
);
9797
}
9898
if (!empty($filename) && !$this->validateURLScheme($filename)) {

lib/internal/Magento/Framework/Serialize/Serializer/Json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function unserialize($string)
3636
{
3737
if ($string === null) {
3838
throw new \InvalidArgumentException(
39-
sprintf('Unable to unserialize value. Error: Parameter must be a string type, null given.')
39+
'Unable to unserialize value. Error: Parameter must be a string type, null given.'
4040
);
4141
}
4242
$result = json_decode($string, true);

lib/internal/Magento/Framework/Serialize/Test/Unit/Serializer/JsonTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public function testSerializeException()
9494
}
9595

9696
/**
97+
* Method to test unserialize exception.
98+
*
99+
* @param string|bool|null $value
100+
* @param string $errorMessage
101+
*
97102
* @dataProvider unserializeExceptionDataProvider
98103
*/
99-
public function testUnserializeException($value)
104+
public function testUnserializeException($value, $errorMessage)
100105
{
101-
$errorMessage = 'Unable to unserialize value.';
102-
103-
if ($value === null) {
104-
$errorMessage = 'Unable to unserialize value. Error: Parameter must be a string type, null given.';
105-
}
106106
$this->expectException('InvalidArgumentException');
107107
$this->expectExceptionMessage($errorMessage);
108108
$this->json->unserialize($value);
@@ -114,10 +114,10 @@ public function testUnserializeException($value)
114114
public function unserializeExceptionDataProvider()
115115
{
116116
return [
117-
[''],
118-
[false],
119-
[null],
120-
['{']
117+
['', 'Unable to unserialize value.'],
118+
[false, 'Unable to unserialize value.'],
119+
[null, 'Unable to unserialize value. Error: Parameter must be a string type, null given.'],
120+
['{', 'Unable to unserialize value.']
121121
];
122122
}
123123
}

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,24 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
3131
/**
3232
* Cache group Tag
3333
*/
34-
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER;
34+
public const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER;
3535

3636
/**
3737
* Prefix for cache key of block
3838
*/
39-
const CACHE_KEY_PREFIX = 'BLOCK_';
39+
public const CACHE_KEY_PREFIX = 'BLOCK_';
4040

4141
/**
42-
* Design
43-
*
4442
* @var \Magento\Framework\View\DesignInterface
4543
*/
4644
protected $_design;
4745

4846
/**
49-
* Session
50-
*
5147
* @var \Magento\Framework\Session\SessionManagerInterface
5248
*/
5349
protected $_session;
5450

5551
/**
56-
* SID Resolver
57-
*
5852
* @var \Magento\Framework\Session\SidResolverInterface
5953
* @deprecated 102.0.5 Not used anymore.
6054
*/
@@ -82,15 +76,11 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
8276
protected $jsLayout = [];
8377

8478
/**
85-
* Request
86-
*
8779
* @var \Magento\Framework\App\RequestInterface
8880
*/
8981
protected $_request;
9082

9183
/**
92-
* Url Builder
93-
*
9484
* @var \Magento\Framework\UrlInterface
9585
*/
9686
protected $_urlBuilder;
@@ -125,29 +115,21 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
125115
protected $_viewConfig;
126116

127117
/**
128-
* Cache State
129-
*
130118
* @var \Magento\Framework\App\Cache\StateInterface
131119
*/
132120
protected $_cacheState;
133121

134122
/**
135-
* Logger
136-
*
137123
* @var \Psr\Log\LoggerInterface
138124
*/
139125
protected $_logger;
140126

141127
/**
142-
* Escaper
143-
*
144128
* @var \Magento\Framework\Escaper
145129
*/
146130
protected $_escaper;
147131

148132
/**
149-
* Filter manager
150-
*
151133
* @var \Magento\Framework\Filter\FilterManager
152134
*/
153135
protected $filterManager;
@@ -954,10 +936,9 @@ public function escapeCss($string)
954936
*/
955937
public function stripTags($data, $allowableTags = null, $allowHtmlEntities = false)
956938
{
957-
return $this->filterManager->stripTags(
958-
$data,
959-
['allowableTags' => $allowableTags, 'escape' => $allowHtmlEntities]
960-
);
939+
$params = ['allowableTags' => $allowableTags, 'escape' => $allowHtmlEntities];
940+
941+
return $data ? $this->filterManager->stripTags($data, $params) : '';
961942
}
962943

963944
/**

0 commit comments

Comments
 (0)