Skip to content

Commit d676d2a

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p7' into delivery-bunch-w21
2 parents 6e83313 + b0c8fb3 commit d676d2a

File tree

13 files changed

+85
-72
lines changed

13 files changed

+85
-72
lines changed

app/code/Magento/MediaStorage/App/Media.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function __construct(
148148
DirectoryList::MEDIA,
149149
Filesystem\DriverPool::FILE
150150
);
151-
$mediaDirectory = trim($mediaDirectory);
151+
$mediaDirectory = $mediaDirectory !== null ? trim($mediaDirectory) : '';
152152
if (!empty($mediaDirectory)) {
153153
// phpcs:ignore Magento2.Functions.DiscouragedFunction
154154
$this->mediaDirectoryPath = str_replace('\\', '/', $file->getRealPath($mediaDirectory));

app/code/Magento/MediaStorage/Helper/File/Media.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
1010

11-
/**
12-
* Class Media
13-
*/
1411
class Media extends \Magento\Framework\App\Helper\AbstractHelper
1512
{
1613
/**
@@ -56,7 +53,7 @@ public function __construct(
5653
*/
5754
public function collectFileInfo($mediaDirectory, $path)
5855
{
59-
$path = ltrim($path, '\\/');
56+
$path = $path !== null ? ltrim($path, '\\/') : '';
6057
$fullPath = $mediaDirectory . '/' . $path;
6158

6259
$dir = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
@@ -71,6 +68,7 @@ public function collectFileInfo($mediaDirectory, $path)
7168
}
7269

7370
$path = str_replace(['/', '\\'], '/', $path);
71+
// phpcs:disable Magento2.Functions.DiscouragedFunction
7472
$directory = dirname($path);
7573
if ($directory == '.') {
7674
$directory = null;

app/code/Magento/MediaStorage/Helper/File/Storage/Database.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* @since 100.0.2
1717
*
1818
* @deprecated Database Media Storage is deprecated
19-
*
2019
*/
2120
class Database extends \Magento\Framework\App\Helper\AbstractHelper
2221
{
@@ -209,8 +208,8 @@ public function getUniqueFilename($directory, $filename)
209208
$directory = $this->_removeAbsPathFromFileName($directory);
210209
if ($this->fileExists($directory . $filename)) {
211210
$index = 1;
212-
$extension = strrchr($filename, '.');
213-
$filenameWoExtension = substr($filename, 0, -1 * strlen($extension));
211+
$extension = $filename !== null ? strrchr($filename, '.') : '';
212+
$filenameWoExtension = $filename !== null ? substr($filename, 0, -1 * strlen($extension)) : '';
214213
while ($this->fileExists($directory . $filenameWoExtension . '_' . $index . $extension)) {
215214
$index++;
216215
}
@@ -248,7 +247,7 @@ public function saveFileToFilesystem($filename)
248247
*/
249248
public function getMediaRelativePath($fullPath)
250249
{
251-
$relativePath = ltrim(str_replace($this->getMediaBaseDir(), '', $fullPath), '\\/');
250+
$relativePath = $fullPath !== null ? ltrim(str_replace($this->getMediaBaseDir(), '', $fullPath), '\\/') : '';
252251
return str_replace('\\', '/', $relativePath);
253252
}
254253

@@ -281,7 +280,7 @@ public function deleteFile($filename)
281280
/**
282281
* Saves uploaded by \Magento\MediaStorage\Model\File\Uploader file to DB with existence tests
283282
*
284-
* param $result should be result from \Magento\MediaStorage\Model\File\Uploader::save() method
283+
* Param $result should be result from \Magento\MediaStorage\Model\File\Uploader::save() method
285284
* Checks in DB, whether uploaded file exists ($result['file'])
286285
* If yes, renames file on FS (!!!!!)
287286
* Saves file with unique name into DB
@@ -294,8 +293,8 @@ public function deleteFile($filename)
294293
public function saveUploadedFile($result)
295294
{
296295
if ($this->checkDbUsage()) {
297-
$path = rtrim(str_replace(['\\', '/'], '/', $result['path']), '/');
298-
$file = '/' . ltrim($result['file'], '\\/');
296+
$path = rtrim(str_replace(['\\', '/'], '/', $result['path'] ?? ''), '/');
297+
$file = '/' . ltrim($result['file'] ?? '', '\\/');
299298

300299
$uniqueResultFile = $this->getUniqueFilename($path, $file);
301300

@@ -313,6 +312,7 @@ public function saveUploadedFile($result)
313312

314313
/**
315314
* Convert full file path to local (as used by model)
315+
*
316316
* If not - returns just a filename
317317
*
318318
* @param string $filename

app/code/Magento/MediaStorage/Model/File/Storage/Directory/Database.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
namespace Magento\MediaStorage\Model\File\Storage\Directory;
88

99
/**
10-
* Class Database
11-
*
1210
* @api
1311
* @since 100.0.2
1412
*
@@ -121,7 +119,7 @@ public function getParentId()
121119
$this->setData('parent_id', $parentId);
122120
}
123121

124-
return $parentId;
122+
return $this->getData('parent_id');
125123
}
126124

127125
/**
@@ -135,7 +133,9 @@ public function createRecursive($path)
135133
$directory = $this->_directoryFactory->create()->loadByPath($path);
136134

137135
if (!$directory->getId()) {
136+
// phpcs:disable Magento2.Functions.DiscouragedFunction
138137
$dirName = basename($path);
138+
// phpcs:disable Magento2.Functions.DiscouragedFunction
139139
$dirPath = dirname($path);
140140

141141
if ($dirPath != '.') {
@@ -196,7 +196,7 @@ public function importDirectories($dirs)
196196
}
197197

198198
try {
199-
$dir['path'] = ltrim($dir['path'], './');
199+
$dir['path'] = ltrim($dir['path'] ?? '', './');
200200
$directory = $this->_directoryFactory->create(['connectionName' => $this->getConnectionName()]);
201201
$directory->setPath($dir['path']);
202202

@@ -251,7 +251,9 @@ public function getSubdirectories($directory)
251251
public function deleteDirectory($dirPath)
252252
{
253253
$dirPath = $this->_coreFileStorageDb->getMediaRelativePath($dirPath);
254+
// phpcs:disable Magento2.Functions.DiscouragedFunction
254255
$name = basename($dirPath);
256+
// phpcs:disable Magento2.Functions.DiscouragedFunction
255257
$path = dirname($dirPath);
256258

257259
if ('.' == $path) {

app/code/Magento/MediaStorage/Model/File/Validator/AvailablePath.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
class AvailablePath extends \Zend_Validate_Abstract
3030
{
31-
const PROTECTED_PATH = 'protectedPath';
31+
public const PROTECTED_PATH = 'protectedPath';
3232

33-
const NOT_AVAILABLE_PATH = 'notAvailablePath';
33+
public const NOT_AVAILABLE_PATH = 'notAvailablePath';
3434

35-
const PROTECTED_LFI = 'protectedLfi';
35+
public const PROTECTED_LFI = 'protectedLfi';
3636

3737
/**
3838
* The path
@@ -42,15 +42,11 @@ class AvailablePath extends \Zend_Validate_Abstract
4242
protected $_value;
4343

4444
/**
45-
* Protected paths
46-
*
4745
* @var string[]
4846
*/
4947
protected $_protectedPaths = [];
5048

5149
/**
52-
* Available paths
53-
*
5450
* @var string[]
5551
*/
5652
protected $_availablePaths = [];
@@ -192,23 +188,26 @@ public function getAvailablePaths()
192188
* @return bool
193189
* @throws \Exception Throw exception on empty both paths masks types
194190
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
191+
* @SuppressWarnings(PHPMD.NPathComplexity)
195192
*/
196193
public function isValid($value)
197194
{
198-
$value = trim($value);
195+
$value = $value !== null ? trim($value) : '';
199196
$this->_setValue($value);
200197

201198
if (!$this->_availablePaths && !$this->_protectedPaths) {
199+
// phpcs:ignore Magento2.Exceptions.DirectThrow
202200
throw new \Exception(__('Please set available and/or protected paths list(s) before validation.'));
203201
}
204202

205-
if (preg_match('#\.\.[\\\/]#', $this->_value)) {
203+
if ($this->_value && preg_match('#\.\.[\\\/]#', $this->_value)) {
206204
$this->_error(self::PROTECTED_LFI, $this->_value);
207205
return false;
208206
}
209207

210208
//validation
211-
$value = str_replace('\\', '/', $this->_value);
209+
$value = str_replace('\\', '/', $this->_value ?? '');
210+
// phpcs:disable Magento2.Functions.DiscouragedFunction
212211
$valuePathInfo = pathinfo(ltrim($value, '\\/'));
213212
if ($valuePathInfo['dirname'] == '.' || $valuePathInfo['dirname'] == '/') {
214213
$valuePathInfo['dirname'] = '';
@@ -229,24 +228,25 @@ public function isValid($value)
229228
/**
230229
* Validate value by path masks
231230
*
232-
* @param array $valuePathInfo Path info from value path
233-
* @param string[] $paths Protected/available paths masks
234-
* @param bool $protected Paths masks is protected?
231+
* @param array $valuePathInfo Path info from value path
232+
* @param string[] $paths Protected/available paths masks
233+
* @param bool $protected Paths masks is protected?
235234
* @return bool
236235
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
237236
* @SuppressWarnings(PHPMD.NPathComplexity)
238237
*/
239238
protected function _isValidByPaths($valuePathInfo, $paths, $protected)
240239
{
241240
foreach ($paths as $path) {
242-
$path = ltrim($path, '\\/');
241+
$path = $path !== null ? ltrim($path, '\\/') : '';
243242
if (!isset($this->_pathsData[$path]['regFilename'])) {
243+
// phpcs:disable Magento2.Functions.DiscouragedFunction
244244
$pathInfo = pathinfo($path);
245245
$options['file_mask'] = $pathInfo['basename'];
246246
if ($pathInfo['dirname'] == '.' || $pathInfo['dirname'] == '/') {
247247
$pathInfo['dirname'] = '';
248248
} else {
249-
$pathInfo['dirname'] = str_replace('\\', '/', $pathInfo['dirname']);
249+
$pathInfo['dirname'] = str_replace('\\', '/', $pathInfo['dirname'] ?? '');
250250
}
251251
$options['dir_mask'] = $pathInfo['dirname'];
252252
$this->_pathsData[$path]['options'] = $options;
@@ -255,17 +255,17 @@ protected function _isValidByPaths($valuePathInfo, $paths, $protected)
255255
}
256256

257257
//file mask
258-
if (false !== strpos($options['file_mask'], '*')) {
258+
if (false !== strpos($options['file_mask'] ?? '', '*')) {
259259
if (!isset($this->_pathsData[$path]['regFilename'])) {
260260
//make regular
261-
$reg = $options['file_mask'];
261+
$reg = $options['file_mask'] ?? '';
262262
$reg = str_replace('.', '\.', $reg);
263263
$reg = str_replace('*', '.*?', $reg);
264264
$reg = "/^({$reg})\$/";
265265
} else {
266266
$reg = $this->_pathsData[$path]['regFilename'];
267267
}
268-
$resultFile = preg_match($reg, $valuePathInfo['basename']);
268+
$resultFile = preg_match($reg, $valuePathInfo['basename'] ?? '');
269269
} else {
270270
$resultFile = $options['file_mask'] == $valuePathInfo['basename'];
271271
}

app/code/Magento/MysqlMq/Model/Driver/Bulk/Exchange.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function ($envelope) {
8888
*/
8989
private function isMatchedBinding(BindingInterface $binding, string $topic): bool
9090
{
91-
$pattern = '/^' . str_replace(['.', '*', '#'], ['\.', '[^.]+?', '(.*?)'], $binding->getTopic()) . '$/';
91+
$pattern = '/^' . str_replace(['.', '*', '#'], ['\.', '[^.]+?', '(.*?)'], $binding->getTopic() ?? '') . '$/';
9292
return preg_match($pattern, $topic) ? true : false;
9393
}
9494
}

app/code/Magento/NewsletterGraphQl/Model/Resolver/SubscribeEmailToNewsletter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function resolve(
8282
array $value = null,
8383
array $args = null
8484
) {
85-
$email = trim($args['email']);
85+
$email = trim($args['email'] ?? '');
8686

8787
if (empty($email)) {
8888
throw new GraphQlInputException(

app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate/CSV/ColumnResolver.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
class ColumnResolver
1010
{
11-
const COLUMN_COUNTRY = 'Country';
12-
const COLUMN_REGION = 'Region/State';
13-
const COLUMN_ZIP = 'Zip/Postal Code';
14-
const COLUMN_WEIGHT = 'Weight (and above)';
15-
const COLUMN_WEIGHT_DESTINATION = 'Weight (and above)';
16-
const COLUMN_PRICE = 'Shipping Price';
11+
public const COLUMN_COUNTRY = 'Country';
12+
public const COLUMN_REGION = 'Region/State';
13+
public const COLUMN_ZIP = 'Zip/Postal Code';
14+
public const COLUMN_WEIGHT = 'Weight (and above)';
15+
public const COLUMN_WEIGHT_DESTINATION = 'Weight (and above)';
16+
public const COLUMN_PRICE = 'Shipping Price';
1717

1818
/**
1919
* @var array
@@ -22,7 +22,7 @@ class ColumnResolver
2222
self::COLUMN_COUNTRY => 0,
2323
self::COLUMN_REGION => 1,
2424
self::COLUMN_ZIP => 2,
25-
self::COLUMN_WEIGHT => 3,
25+
self::COLUMN_WEIGHT => 3, // @phpstan-ignore-line
2626
self::COLUMN_WEIGHT_DESTINATION => 3,
2727
self::COLUMN_PRICE => 4,
2828
];
@@ -44,6 +44,8 @@ public function __construct(array $headers, array $columns = [])
4444
}
4545

4646
/**
47+
* Method to get column value.
48+
*
4749
* @param string $column
4850
* @param array $values
4951
* @return string|int|float|null
@@ -65,6 +67,6 @@ public function getColumnValue($column, array $values)
6567
throw new ColumnNotFoundException(__('Column "%1" not found', $column));
6668
}
6769

68-
return trim($values[$columnIndex]);
70+
return trim($values[$columnIndex] ?? '');
6971
}
7072
}

app/code/Magento/PageCache/Model/Config.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Filesystem;
11+
use Magento\Framework\HTTP\PhpEnvironment\Request;
1112
use Magento\Framework\Module\Dir;
1213
use Magento\Framework\Serialize\Serializer\Json;
14+
use Magento\PageCache\Model\Cache\Type;
1315
use Magento\PageCache\Model\Varnish\VclGeneratorFactory;
1416

1517
/**
@@ -158,7 +160,7 @@ public function getVclFile($vclTemplatePath)
158160
$version = 4;
159161
}
160162
$sslOffloadedHeader = $this->_scopeConfig->getValue(
161-
\Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER
163+
Request::XML_PATH_OFFLOADER_HEADER
162164
);
163165
$vclGenerator = $this->vclGeneratorFactory->create(
164166
[
@@ -192,7 +194,7 @@ protected function _getReplacements()
192194
'/* {{ ssl_offloaded_header }} */' => str_replace(
193195
'_',
194196
'-',
195-
$this->_scopeConfig->getValue(\Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER)
197+
$this->_scopeConfig->getValue(Request::XML_PATH_OFFLOADER_HEADER) ?? ''
196198
),
197199
'/* {{ grace_period }} */' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_GRACE_PERIOD)
198200
];
@@ -227,6 +229,7 @@ protected function _getAccessList()
227229

228230
/**
229231
* Get regexs for design exceptions
232+
*
230233
* Different browser user-agents may use different themes
231234
* Varnish supports regex with internal modifiers only so
232235
* we have to convert "/pattern/iU" into "(?Ui)pattern"
@@ -246,7 +249,7 @@ protected function _getDesignExceptions()
246249
if ($expressions) {
247250
$rules = array_values($this->serializer->unserialize($expressions));
248251
foreach ($rules as $i => $rule) {
249-
if (preg_match('/^[\W]{1}(.*)[\W]{1}(\w+)?$/', $rule['regexp'], $matches)) {
252+
if (preg_match('/^[\W]{1}(.*)[\W]{1}(\w+)?$/', $rule['regexp'] ?? '', $matches)) {
250253
if (!empty($matches[2])) {
251254
$pattern = sprintf("(?%s)%s", $matches[2], $matches[1]);
252255
} else {
@@ -267,6 +270,6 @@ protected function _getDesignExceptions()
267270
*/
268271
public function isEnabled()
269272
{
270-
return $this->_cacheState->isEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);
273+
return $this->_cacheState->isEnabled(Type::TYPE_IDENTIFIER);
271274
}
272275
}

app/code/Magento/PageCache/Model/Layout/MergePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
public function beforeValidateUpdate(\Magento\Framework\View\Model\Layout\Merge $subject, $handle, $updateXml)
4343
{
4444
if (in_array($handle, $this->entitySpecificHandlesList->getHandles())
45-
&& (strpos($updateXml, 'ttl=') !== false)
45+
&& ($updateXml && strpos($updateXml, 'ttl=') !== false)
4646
) {
4747
throw new \LogicException(
4848
"Handle '{$handle}' must not contain blocks with 'ttl' attribute specified. "

0 commit comments

Comments
 (0)