Skip to content

Commit 7ded2f9

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p5' into delivery-bunch-w21
2 parents 3e331de + 52b7cc6 commit 7ded2f9

File tree

15 files changed

+92
-92
lines changed

15 files changed

+92
-92
lines changed

app/code/Magento/Downloadable/Helper/Download.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ class Download extends \Magento\Framework\App\Helper\AbstractHelper
2222
/**
2323
* Link type for url
2424
*/
25-
const LINK_TYPE_URL = 'url';
25+
public const LINK_TYPE_URL = 'url';
2626

2727
/**
2828
* Link type for file
2929
*/
30-
const LINK_TYPE_FILE = 'file';
30+
public const LINK_TYPE_FILE = 'file';
3131

3232
/**
3333
* Config path to content disposition
3434
*/
35-
const XML_PATH_CONTENT_DISPOSITION = 'catalog/downloadable/content_disposition';
35+
public const XML_PATH_CONTENT_DISPOSITION = 'catalog/downloadable/content_disposition';
3636

3737
/**
3838
* Type of link
@@ -42,8 +42,6 @@ class Download extends \Magento\Framework\App\Helper\AbstractHelper
4242
protected $_linkType = self::LINK_TYPE_FILE;
4343

4444
/**
45-
* Resource file
46-
*
4745
* @var string
4846
*/
4947
protected $_resourceFile = null;
@@ -70,8 +68,6 @@ class Download extends \Magento\Framework\App\Helper\AbstractHelper
7068
protected $_contentType = 'application/octet-stream';
7169

7270
/**
73-
* File name
74-
*
7571
* @var string
7672
*/
7773
protected $_fileName = 'download';
@@ -84,8 +80,6 @@ class Download extends \Magento\Framework\App\Helper\AbstractHelper
8480
protected $_coreFileStorageDb;
8581

8682
/**
87-
* Downloadable file
88-
*
8983
* @var \Magento\Downloadable\Helper\File
9084
*/
9185
protected $_downloadableFile;
@@ -255,7 +249,7 @@ public function setResource($resourceFile, $linkType = self::LINK_TYPE_FILE)
255249
{
256250
if (self::LINK_TYPE_FILE == $linkType) {
257251
//check LFI protection
258-
if (preg_match('#\.\.[\\\/]#', $resourceFile)) {
252+
if ($resourceFile && preg_match('#\.\.[\\\/]#', $resourceFile)) {
259253
throw new \InvalidArgumentException(
260254
'Requested file may not include parent directory traversal ("../", "..\\" notation)'
261255
);

app/code/Magento/Downloadable/Helper/File.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function ensureFileInFilesystem($file)
136136
*/
137137
protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
138138
{
139-
if (strrpos($file, '.tmp') == strlen($file) - 4) {
139+
if ($file && strrpos($file, '.tmp') == strlen($file) - 4) {
140140
$file = substr($file, 0, strlen($file) - 4);
141141
}
142142
// phpcs:ignore Magento2.Functions.DiscouragedFunction
@@ -165,8 +165,8 @@ protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
165165
*/
166166
public function getFilePath($path, $file)
167167
{
168-
$path = rtrim($path, '/');
169-
$file = ltrim($file, '/');
168+
$path = $path !== null ? rtrim($path, '/') : '';
169+
$file = $file !== null ? ltrim($file, '/') : '';
170170

171171
return $path . '/' . $file;
172172
}
@@ -179,7 +179,7 @@ public function getFilePath($path, $file)
179179
*/
180180
public function getFileFromPathFile($pathFile)
181181
{
182-
$file = substr($pathFile, strrpos($pathFile, '/') + 1);
182+
$file = $pathFile !== null ? substr($pathFile, strrpos($pathFile, '/') + 1) : '';
183183

184184
return $file;
185185
}
@@ -203,7 +203,7 @@ public function getFileSize($file)
203203
*/
204204
public function getFileType($filePath)
205205
{
206-
$ext = substr($filePath, strrpos($filePath, '.') + 1);
206+
$ext = $filePath !== null ? substr($filePath, strrpos($filePath, '.') + 1) : '';
207207
return $this->_getFileTypeByExt($ext);
208208
}
209209

app/code/Magento/Downloadable/Model/File/ContentValidator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ContentValidator
1919
*/
2020
public function isValid(ContentInterface $fileContent)
2121
{
22+
// phpcs:disable Generic.PHP.NoSilencedErrors,Magento2.Functions.DiscouragedFunction
2223
$decodedContent = @base64_decode($fileContent->getFileData(), true);
2324
if (empty($decodedContent)) {
2425
throw new InputException(__('Provided content must be valid base64 encoded data.'));
@@ -39,7 +40,7 @@ public function isValid(ContentInterface $fileContent)
3940
protected function isFileNameValid($fileName)
4041
{
4142
// Cannot contain \ / : * ? " < > |
42-
if (!preg_match('/^[^\\/?*:";<>()|{}\\\\]+$/', $fileName)) {
43+
if (!$fileName || !preg_match('/^[^\\/?*:";<>()|{}\\\\]+$/', $fileName)) {
4344
return false;
4445
}
4546
return true;

app/code/Magento/Downloadable/Model/Product/Price.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
namespace Magento\Downloadable\Model\Product;
1313

14+
/**
15+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
16+
*/
1417
class Price extends \Magento\Catalog\Model\Product\Type\Price
1518
{
1619
/**
@@ -35,7 +38,7 @@ public function getFinalPrice($qty, $product)
3538
if ($linksIds = $product->getCustomOption('downloadable_link_ids')) {
3639
$linkPrice = 0;
3740
$links = $product->getTypeInstance()->getLinks($product);
38-
foreach (explode(',', $linksIds->getValue()) as $linkId) {
41+
foreach (explode(',', $linksIds->getValue() ?? '') as $linkId) {
3942
if (isset($links[$linkId])) {
4043
$linkPrice += $links[$linkId]->getPrice();
4144
}

app/code/Magento/Downloadable/Model/Product/Type.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
*/
1919
class Type extends \Magento\Catalog\Model\Product\Type\Virtual
2020
{
21-
const TYPE_DOWNLOADABLE = 'downloadable';
21+
public const TYPE_DOWNLOADABLE = 'downloadable';
2222

2323
/**
24-
* Downloadable file
25-
*
2624
* @var \Magento\Downloadable\Helper\File
2725
*/
2826
protected $_downloadableFile = null;
@@ -275,8 +273,7 @@ public function checkProductBuyState($product)
275273
}
276274

277275
/**
278-
* Prepare additional options/information for order item which will be
279-
* created from this product
276+
* Prepare additional options/information for order item which will be created from this product
280277
*
281278
* @param \Magento\Catalog\Model\Product $product
282279
* @return array
@@ -287,7 +284,7 @@ public function getOrderOptions($product)
287284
if ($linkIds = $product->getCustomOption('downloadable_link_ids')) {
288285
$linkOptions = [];
289286
$links = $this->getLinks($product);
290-
foreach (explode(',', $linkIds->getValue()) as $linkId) {
287+
foreach (explode(',', $linkIds->getValue() ?? '') as $linkId) {
291288
if (isset($links[$linkId])) {
292289
$linkOptions[] = $linkId;
293290
}
@@ -303,6 +300,7 @@ public function getOrderOptions($product)
303300

304301
/**
305302
* Retrieve additional searchable data from type instance
303+
*
306304
* Using based on product id and store_id data
307305
*
308306
* @param \Magento\Catalog\Model\Product $product
@@ -408,6 +406,7 @@ public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
408406

409407
/**
410408
* Prepare product and its configuration to be added to some products list.
409+
*
411410
* Perform standard preparation process and then prepare options for downloadable links.
412411
*
413412
* @param \Magento\Framework\DataObject $buyRequest
@@ -458,6 +457,8 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
458457
}
459458

460459
/**
460+
* Method to create link.
461+
*
461462
* @return \Magento\Downloadable\Model\Link
462463
*/
463464
protected function _createLink()
@@ -466,6 +467,8 @@ protected function _createLink()
466467
}
467468

468469
/**
470+
* Method to create sample.
471+
*
469472
* @return \Magento\Downloadable\Model\Sample
470473
*/
471474
protected function _createSample()

app/code/Magento/Downloadable/Model/Quote/Item/CartItemProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(
5858
}
5959

6060
/**
61-
* {@inheritdoc}
61+
* @inheritdoc
6262
*/
6363
public function convertToBuyRequest(CartItemInterface $cartItem)
6464
{
@@ -88,7 +88,7 @@ public function processOptions(CartItemInterface $cartItem)
8888
$downloadableLinkIds = [];
8989
$option = $cartItem->getOptionByCode('downloadable_link_ids');
9090
if (!empty($option)) {
91-
$downloadableLinkIds = explode(',', $option->getValue());
91+
$downloadableLinkIds = explode(',', $option->getValue() ?? '');
9292
}
9393

9494
$downloadableOption = $this->downloadableOptionFactory->create();

app/code/Magento/Downloadable/Observer/IsAllowedGuestCheckoutObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function checkForShareableLinks(CartItemInterface $item, int $storeId):
104104
$option = $item->getOptionByCode('downloadable_link_ids');
105105

106106
if (!empty($option)) {
107-
$downloadableLinkIds = explode(',', $option->getValue());
107+
$downloadableLinkIds = explode(',', $option->getValue() ?? '');
108108

109109
$linkCollection = $this->linkCollectionFactory->create();
110110
$linkCollection->addFieldToFilter('link_id', ['in' => $downloadableLinkIds]);

app/code/Magento/Downloadable/Setup/Patch/Data/InstallDownloadableAttributes.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@
66

77
namespace Magento\Downloadable\Setup\Patch\Data;
88

9+
use Magento\Catalog\Model\Product;
10+
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
911
use Magento\Eav\Setup\EavSetup;
1012
use Magento\Eav\Setup\EavSetupFactory;
11-
use Magento\Framework\App\ResourceConnection;
1213
use Magento\Framework\Setup\ModuleDataSetupInterface;
1314
use Magento\Framework\Setup\Patch\DataPatchInterface;
1415
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1516

16-
/**
17-
* Class InstallDownloadableAttributes
18-
* @package Magento\Downloadable\Setup\Patch
19-
*/
2017
class InstallDownloadableAttributes implements DataPatchInterface, PatchVersionInterface
2118
{
2219
/**
23-
* @var \Magento\Framework\Setup\ModuleDataSetupInterface
20+
* @var ModuleDataSetupInterface
2421
*/
2522
private $moduleDataSetup;
2623

@@ -43,7 +40,8 @@ public function __construct(
4340
}
4441

4542
/**
46-
* {@inheritdoc}
43+
* @inheritdoc
44+
*
4745
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
4846
*/
4947
public function apply()
@@ -54,7 +52,7 @@ public function apply()
5452
* Add attributes to the eav/attribute table
5553
*/
5654
$eavSetup->addAttribute(
57-
\Magento\Catalog\Model\Product::ENTITY,
55+
Product::ENTITY,
5856
'links_purchased_separately',
5957
[
6058
'type' => 'int',
@@ -64,7 +62,7 @@ public function apply()
6462
'input' => '',
6563
'class' => '',
6664
'source' => '',
67-
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
65+
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
6866
'visible' => false,
6967
'required' => true,
7068
'user_defined' => false,
@@ -80,7 +78,7 @@ public function apply()
8078
);
8179

8280
$eavSetup->addAttribute(
83-
\Magento\Catalog\Model\Product::ENTITY,
81+
Product::ENTITY,
8482
'samples_title',
8583
[
8684
'type' => 'varchar',
@@ -90,7 +88,7 @@ public function apply()
9088
'input' => '',
9189
'class' => '',
9290
'source' => '',
93-
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
91+
'global' => ScopedAttributeInterface::SCOPE_STORE,
9492
'visible' => false,
9593
'required' => true,
9694
'user_defined' => false,
@@ -104,7 +102,7 @@ public function apply()
104102
]
105103
);
106104
$eavSetup->addAttribute(
107-
\Magento\Catalog\Model\Product::ENTITY,
105+
Product::ENTITY,
108106
'links_title',
109107
[
110108
'type' => 'varchar',
@@ -114,7 +112,7 @@ public function apply()
114112
'input' => '',
115113
'class' => '',
116114
'source' => '',
117-
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
115+
'global' => ScopedAttributeInterface::SCOPE_STORE,
118116
'visible' => false,
119117
'required' => true,
120118
'user_defined' => false,
@@ -128,7 +126,7 @@ public function apply()
128126
]
129127
);
130128
$eavSetup->addAttribute(
131-
\Magento\Catalog\Model\Product::ENTITY,
129+
Product::ENTITY,
132130
'links_exist',
133131
[
134132
'type' => 'int',
@@ -166,38 +164,40 @@ public function apply()
166164
foreach ($fieldList as $field) {
167165
$applyTo = explode(
168166
',',
169-
$eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
167+
$eavSetup->getAttribute(Product::ENTITY, $field, 'apply_to') ?? ''
170168
);
171169
if (!in_array('downloadable', $applyTo)) {
172170
$applyTo[] = 'downloadable';
173171
$eavSetup->updateAttribute(
174-
\Magento\Catalog\Model\Product::ENTITY,
172+
Product::ENTITY,
175173
$field,
176174
'apply_to',
177175
implode(',', $applyTo)
178176
);
179177
}
180178
}
179+
180+
return $this;
181181
}
182182

183183
/**
184-
* {@inheritdoc}
184+
* @inheritdoc
185185
*/
186186
public static function getDependencies()
187187
{
188188
return [];
189189
}
190190

191191
/**
192-
* {@inheritdoc}
192+
* @inheritdoc
193193
*/
194194
public static function getVersion()
195195
{
196196
return '2.0.0';
197197
}
198198

199199
/**
200-
* {@inheritdoc}
200+
* @inheritdoc
201201
*/
202202
public function getAliases()
203203
{

app/code/Magento/DownloadableGraphQl/Resolver/DownloadableCartItem/Links.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function resolve(
6464
$product = $quoteItem->getProduct();
6565

6666
$selectedLinksIds = $product->getLinksPurchasedSeparately()
67-
? explode(',', $quoteItem->getOptionByCode('downloadable_link_ids')->getValue()) : [];
67+
? explode(',', $quoteItem->getOptionByCode('downloadable_link_ids')->getValue() ?? '') : [];
6868
$links = $this->getDownloadableProductLinks->execute($product, $selectedLinksIds);
6969

7070
$data = $this->convertLinksToArray->execute($links);

0 commit comments

Comments
 (0)