Skip to content

Commit 00641d0

Browse files
committed
Fixed code by recommendation
1 parent 3bed679 commit 00641d0

File tree

8 files changed

+69
-73
lines changed

8 files changed

+69
-73
lines changed

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Renderer/CurrencyTest.php

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function setUp(): void
7272

7373
$this->_curLocatorMock = $this->createMock(DefaultLocator::class);
7474
$this->_columnMock = $this->getMockBuilder(Column::class)
75-
->addMethods(['getIndex'])
75+
->addMethods(['getIndex', 'getCurrency', 'getRateField'])
7676
->disableOriginalConstructor()
7777
->getMock();
7878
$this->_columnMock->expects($this->any())->method('getIndex')->willReturn('columnIndex');
@@ -115,45 +115,25 @@ protected function tearDown(): void
115115
*/
116116
public function testRenderWithDefaultCurrency()
117117
{
118-
$this->_currencyMock->expects(
119-
$this->once()
120-
)->method(
121-
'getRate'
122-
)->with(
123-
'defaultCurrency'
124-
)->willReturn(
125-
1.5
126-
);
127-
128-
$this->_curLocatorMock->expects(
129-
$this->any()
130-
)->method(
131-
'getDefaultCurrency'
132-
)->with(
133-
$this->_requestMock
134-
)->willReturn(
135-
'defaultCurrency'
136-
);
137-
118+
$this->_currencyMock->expects($this->once())
119+
->method('getRate')
120+
->with('defaultCurrency')
121+
->willReturn(1.5);
122+
$this->_curLocatorMock->expects($this->any())
123+
->method('getDefaultCurrency')
124+
->with($this->_requestMock)
125+
->willReturn('defaultCurrency');
138126
$currLocaleMock = $this->createMock(\Zend_Currency::class);
139-
$currLocaleMock->expects(
140-
$this->once()
141-
)->method(
142-
'toCurrency'
143-
)->with(
144-
15.0000
145-
)->willReturn(
146-
'15USD'
147-
);
148-
$this->_localeMock->expects(
149-
$this->once()
150-
)->method(
151-
'getCurrency'
152-
)->with(
153-
'defaultCurrency'
154-
)->willReturn(
155-
$currLocaleMock
156-
);
127+
$currLocaleMock->expects($this->once())
128+
->method('toCurrency')
129+
->with(15.0000)
130+
->willReturn('15USD');
131+
$this->_localeMock->expects($this->once())
132+
->method('getCurrency')
133+
->with('defaultCurrency')
134+
->willReturn($currLocaleMock);
135+
$this->_columnMock->method('getCurrency')->willReturn('USD');
136+
$this->_columnMock->method('getRateField')->willReturn('test_rate_field');
157137

158138
$this->assertEquals('15USD', $this->_blockCurrency->render($this->_row));
159139
}

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,9 @@ public function notAvailableOptionProvider(): array
27862786
private function expectProductEntityMetadata(): void
27872787
{
27882788
$entityMetadataMock = $this->getMockBuilder(EntityMetadataInterface::class)
2789+
->onlyMethods(['getLinkField'])
27892790
->getMockForAbstractClass();
2791+
$entityMetadataMock->method('getLinkField')->willReturn('test_link_field');
27902792
$this->metadataPool->expects($this->any())->method('getMetadata')
27912793
->with(ProductInterface::class)
27922794
->willReturn($entityMetadataMock);

app/code/Magento/Catalog/Test/Unit/Block/Widget/LinkTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\ResourceModel\AbstractResource;
1313
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1414
use Magento\Framework\App\Config\ReinitableConfigInterface;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1516
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1617
use Magento\Framework\Url;
1718
use Magento\Framework\Url\ModifierInterface;
@@ -178,6 +179,7 @@ public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo(
178179
->willReturnMap(
179180
[
180181
[Store::XML_PATH_USE_REWRITES, ReinitableConfigInterface::SCOPE_TYPE_DEFAULT, null, true],
182+
[Store::XML_PATH_UNSECURE_BASE_LINK_URL, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, ''],
181183
[
182184
Store::XML_PATH_STORE_IN_URL,
183185
ReinitableConfigInterface::SCOPE_TYPE_DEFAULT,

app/code/Magento/Catalog/Test/Unit/Model/Category/Attribute/Backend/ImageTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ public function testBeforeSaveTemporaryAttribute()
325325
*/
326326
public function testBeforeSaveAttributeStringValue()
327327
{
328+
$this->attribute->method('getName')->willReturn('test_attribute_name');
328329
$model = $this->objectManager->getObject(Image::class);
329330
$model->setAttribute($this->attribute);
330331

@@ -392,6 +393,7 @@ public function attributeValueDataProvider()
392393
*/
393394
public function testBeforeSaveWithAdditionalData($value)
394395
{
396+
$this->attribute->method('getName')->willReturn('test_attribute_name');
395397
$model = $this->setUpModelForTests();
396398

397399
$this->imageUploader->expects($this->never())
@@ -416,6 +418,7 @@ public function testBeforeSaveWithAdditionalData($value)
416418
*/
417419
public function testBeforeSaveWithoutAdditionalData($value)
418420
{
421+
$this->attribute->method('getName')->willReturn('test_attribute_name');
419422
$model = $this->setUpModelForTests();
420423

421424
$this->imageUploader->expects($this->never())

app/code/Magento/Store/Model/Store.php

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,89 +45,89 @@ class Store extends AbstractExtensibleModel implements
4545
/**
4646
* Store Id key name
4747
*/
48-
public const STORE_ID = 'store_id';
48+
const STORE_ID = 'store_id';
4949

5050
/**
5151
* Entity name
5252
*/
53-
public const ENTITY = 'store';
53+
const ENTITY = 'store';
5454

5555
/**
5656
* Parameter used to determine app context.
5757
*/
58-
public const CUSTOM_ENTRY_POINT_PARAM = 'custom_entry_point';
58+
const CUSTOM_ENTRY_POINT_PARAM = 'custom_entry_point';
5959

6060
/**#@+
6161
* Configuration paths
6262
*/
63-
public const XML_PATH_STORE_IN_URL = 'web/url/use_store';
63+
const XML_PATH_STORE_IN_URL = 'web/url/use_store';
6464

65-
public const XML_PATH_USE_REWRITES = 'web/seo/use_rewrites';
65+
const XML_PATH_USE_REWRITES = 'web/seo/use_rewrites';
6666

67-
public const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
67+
const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
6868

69-
public const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';
69+
const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';
7070

71-
public const XML_PATH_SECURE_IN_FRONTEND = 'web/secure/use_in_frontend';
71+
const XML_PATH_SECURE_IN_FRONTEND = 'web/secure/use_in_frontend';
7272

73-
public const XML_PATH_SECURE_IN_ADMINHTML = 'web/secure/use_in_adminhtml';
73+
const XML_PATH_SECURE_IN_ADMINHTML = 'web/secure/use_in_adminhtml';
7474

75-
public const XML_PATH_ENABLE_HSTS = 'web/secure/enable_hsts';
75+
const XML_PATH_ENABLE_HSTS = 'web/secure/enable_hsts';
7676

77-
public const XML_PATH_ENABLE_UPGRADE_INSECURE = 'web/secure/enable_upgrade_insecure';
77+
const XML_PATH_ENABLE_UPGRADE_INSECURE = 'web/secure/enable_upgrade_insecure';
7878

79-
public const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
79+
const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
8080

81-
public const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
81+
const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
8282

83-
public const XML_PATH_SECURE_BASE_STATIC_URL = 'web/secure/base_static_url';
83+
const XML_PATH_SECURE_BASE_STATIC_URL = 'web/secure/base_static_url';
8484

85-
public const XML_PATH_UNSECURE_BASE_STATIC_URL = 'web/unsecure/base_static_url';
85+
const XML_PATH_UNSECURE_BASE_STATIC_URL = 'web/unsecure/base_static_url';
8686

87-
public const XML_PATH_SECURE_BASE_MEDIA_URL = 'web/secure/base_media_url';
87+
const XML_PATH_SECURE_BASE_MEDIA_URL = 'web/secure/base_media_url';
8888

89-
public const XML_PATH_UNSECURE_BASE_MEDIA_URL = 'web/unsecure/base_media_url';
89+
const XML_PATH_UNSECURE_BASE_MEDIA_URL = 'web/unsecure/base_media_url';
9090

91-
public const XML_PATH_PRICE_SCOPE = 'catalog/price/scope';
91+
const XML_PATH_PRICE_SCOPE = 'catalog/price/scope';
9292

9393
/**#@-*/
9494

9595
/**#@+
9696
* Price scope constants
9797
*/
98-
public const PRICE_SCOPE_GLOBAL = 0;
98+
const PRICE_SCOPE_GLOBAL = 0;
9999

100-
public const PRICE_SCOPE_WEBSITE = 1;
100+
const PRICE_SCOPE_WEBSITE = 1;
101101

102102
/**#@-*/
103103

104-
public const ADMIN_CODE = 'admin';
104+
const ADMIN_CODE = 'admin';
105105

106106
/**
107107
* Tag to use to cache stores.
108108
*/
109-
public const CACHE_TAG = 'store';
109+
const CACHE_TAG = 'store';
110110

111111
/**
112112
* Script name, which returns all the images
113113
*/
114-
public const MEDIA_REWRITE_SCRIPT = 'get.php/';
114+
const MEDIA_REWRITE_SCRIPT = 'get.php/';
115115

116116
/**
117117
* A placeholder for generating base URL
118118
*/
119-
public const BASE_URL_PLACEHOLDER = '{{base_url}}';
119+
const BASE_URL_PLACEHOLDER = '{{base_url}}';
120120

121121
/**
122122
* Identifier of default store
123123
* used for loading data of default scope
124124
*/
125-
public const DEFAULT_STORE_ID = 0;
125+
const DEFAULT_STORE_ID = 0;
126126

127127
/**
128128
* Default store Id (for install)
129129
*/
130-
public const DISTRO_STORE_ID = 1;
130+
const DISTRO_STORE_ID = 1;
131131

132132
/**
133133
* @var \Magento\Framework\App\Cache\Type\Config
@@ -156,6 +156,8 @@ class Store extends AbstractExtensibleModel implements
156156
protected $_eventObject = 'store';
157157

158158
/**
159+
* Price filter
160+
*
159161
* @var \Magento\Directory\Model\Currency\Filter
160162
*/
161163
protected $_priceFilter;
@@ -182,11 +184,15 @@ class Store extends AbstractExtensibleModel implements
182184
protected $_dirCache = [];
183185

184186
/**
187+
* URL cache
188+
*
185189
* @var array
186190
*/
187191
protected $_urlCache = [];
188192

189193
/**
194+
* Base URL cache
195+
*
190196
* @var array
191197
*/
192198
protected $_baseUrlCache = [];
@@ -250,6 +256,8 @@ class Store extends AbstractExtensibleModel implements
250256
protected $_configDataResource;
251257

252258
/**
259+
* Core file storage database
260+
*
253261
* @var \Magento\MediaStorage\Helper\File\Storage\Database
254262
*/
255263
protected $_coreFileStorageDatabase = null;
@@ -658,13 +666,12 @@ public function getBaseUrl($type = UrlInterface::URL_TYPE_LINK, $secure = null)
658666
throw new \InvalidArgumentException('Invalid base url type');
659667
}
660668

661-
if (is_string($url) && strpos($url, self::BASE_URL_PLACEHOLDER) !== false) {
669+
if (false !== strpos($url, self::BASE_URL_PLACEHOLDER)) {
662670
$url = str_replace(self::BASE_URL_PLACEHOLDER, $this->_request->getDistroBaseUrl(), $url);
663671
}
664672

665-
$url = is_string($url) ? rtrim($url, '/') : '';
666673
$this->_baseUrlCache[$cacheKey] = $this->getUrlModifier()->execute(
667-
$url . '/',
674+
rtrim($url, '/') . '/',
668675
\Magento\Framework\Url\ModifierInterface::MODE_BASE
669676
);
670677
}

app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Catalog/Category/ChooserTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ protected function setUp(): void
8383

8484
$this->childNode = $this->getMockBuilder(Node::class)
8585
->addMethods(['getLevel'])
86-
->onlyMethods(['hasChildren'])
86+
->onlyMethods(['hasChildren', 'getIdField'])
8787
->disableOriginalConstructor()
8888
->getMock();
8989
$this->rootNode = $this->getMockBuilder(Node::class)
9090
->addMethods(['getLevel'])
91-
->onlyMethods(['hasChildren', 'getChildren'])
91+
->onlyMethods(['hasChildren', 'getChildren', 'getIdField'])
9292
->disableOriginalConstructor()
9393
->getMock();
9494
$this->categoryTree = $this->createMock(Tree::class);
@@ -115,6 +115,8 @@ public function testGetTreeHasLevelField()
115115
]
116116
);
117117

118+
$this->rootNode->method('getIdField')->willReturn('test_id_field');
119+
$this->childNode->method('getIdField')->willReturn('test_id_field');
118120
$this->childNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($level);
119121

120122
$this->rootNode->expects($this->atLeastOnce())->method('getLevel')->willReturn($rootLevel);

app/code/Magento/Wishlist/Test/Unit/Model/WishlistTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ public function testLoadByCustomerId()
233233
$this->eventDispatcher->expects($this->any())
234234
->method('dispatch');
235235
$this->resource->expects($this->any())
236-
->method('getCustomerIdFieldName');
236+
->method('getCustomerIdFieldName')
237+
->willReturn('test_customer_id');
237238
$this->resource->expects($this->once())
238239
->method('load')
239240
->with($this->logicalOr($this->wishlist, $customerId, $customerIdFieldName));

lib/internal/Magento/Framework/DataObject.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function unsetData($key = null)
120120
* @param string $key
121121
* @param string|int $index
122122
* @return mixed
123-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
124123
*/
125124
public function getData($key = '', $index = null)
126125
{
@@ -129,7 +128,7 @@ public function getData($key = '', $index = null)
129128
}
130129

131130
/* process a/b/c key as ['a']['b']['c'] */
132-
if (is_string($key) && strpos($key, '/') !== false) {
131+
if (strpos($key, '/') !== false) {
133132
$data = $this->getDataByPath($key);
134133
} else {
135134
$data = $this->_getData($key);

0 commit comments

Comments
 (0)