Skip to content

Commit 56e2487

Browse files
committed
AC-3162 fixed logic affected by "RFC: Deprecate passing null" issue
1 parent 629e9d9 commit 56e2487

File tree

12 files changed

+35
-41
lines changed

12 files changed

+35
-41
lines changed

lib/internal/Magento/Framework/Filter/Template/Tokenizer/AbstractTokenizer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ abstract class AbstractTokenizer
3333
*/
3434
public function next()
3535
{
36-
if ($this->_currentIndex + 1 >= strlen($this->_string)) {
36+
$stringLength = $this->_string !== null ? strlen($this->_string) : 0;
37+
if ($this->_currentIndex + 1 >= $stringLength) {
3738
return false;
3839
}
3940

@@ -115,7 +116,7 @@ public function reset()
115116
*/
116117
public function isWhiteSpace()
117118
{
118-
return $this->_string === '' ?: trim($this->char()) !== $this->char();
119+
return $this->_string === '' ?: trim((string)$this->char()) !== $this->char();
119120
}
120121

121122
/**

lib/internal/Magento/Framework/Filter/VariableResolver/StrictResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function handleDataAccess(int $i, Template $filter, array $templateVaria
8686
$stackArgs[$i]['variable'] = $stackArgs[$i - 1]['variable']
8787
->getData($stackArgs[$i]['name']);
8888
}
89-
} elseif ($stackArgs[$i]['type'] == 'method' && substr($stackArgs[$i]['name'], 0, 3) == 'get') {
89+
} elseif ($stackArgs[$i]['type'] == 'method' && substr($stackArgs[$i]['name'] ?? '', 0, 3) == 'get') {
9090
$this->handleGetterMethod($i, $filter, $templateVariables, $stackArgs);
9191
}
9292
}

lib/internal/Magento/Framework/GraphQl/Config/Element/FieldFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public function createFromConfigData(
4747
$isList = false;
4848

4949
//check if type ends with []
50-
if ($fieldType[strlen($fieldType) - 2] == '[' && $fieldType[strlen($fieldType) - 1] == ']') {
50+
if ($fieldType[strlen((string)$fieldType) - 2] == '[' && $fieldType[strlen((string)$fieldType) - 1] == ']') {
5151
$isList = true;
52-
$fieldData['type'] = str_replace('[]', '', $fieldData['type']);
53-
$fieldData['itemType'] = str_replace('[]', '', $fieldData['type']);
52+
$fieldData['type'] = str_replace('[]', '', $fieldData['type'] ?? '');
53+
$fieldData['itemType'] = str_replace('[]', '', $fieldData['type'] ?? '');
5454
}
5555

5656
return $this->objectManager->create(

lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ private function parseTypesWithUnionHandling(string $graphQlSchemaContent): arra
236236
$unionTypes = array_filter(
237237
$types,
238238
function ($t) {
239-
return (strpos($t, 'union ') !== false) && (strpos($t, PHP_EOL . PHP_EOL) !== false);
239+
return (strpos((string)$t, 'union ') !== false) && (strpos((string)$t, PHP_EOL . PHP_EOL) !== false);
240240
}
241241
);
242242

243243
foreach ($unionTypes as $type => $schema) {
244-
$splitSchema = explode(PHP_EOL . PHP_EOL, $schema);
244+
$splitSchema = explode(PHP_EOL . PHP_EOL, (string)$schema);
245245
// Get the type data at the bottom, this will be the additional type data not related to the union
246246
$additionalTypeSchema = end($splitSchema);
247247
// Parse the additional type from the bottom so we can have its type key => schema pair
@@ -338,6 +338,7 @@ private function convertInterfacesToAnnotations(string $graphQlSchemaContent): s
338338

339339
if (!empty($allMatchesForImplements)) {
340340
foreach (array_unique($allMatchesForImplements[0]) as $implementsString) {
341+
$implementsString = $implementsString ?? '';
341342
$implementsStatementString = preg_replace(
342343
"/{$spacePattern}{$implementsKindsPattern}{$spacePattern}/m",
343344
'',

lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader/Reader/EnumType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function read(\GraphQL\Type\Definition\Type $typeMeta) : array
4444
];
4545
foreach ($typeMeta->getValues() as $enumValueMeta) {
4646
$result['items'][$enumValueMeta->value] = [
47-
'name' => strtolower($enumValueMeta->name),
47+
'name' => $enumValueMeta->name !== null ? strtolower($enumValueMeta->name) : '',
4848
'_value' => $enumValueMeta->value,
4949
'description' => $enumValueMeta->description,
5050
'deprecationReason' =>$enumValueMeta->deprecationReason

lib/internal/Magento/Framework/HTTP/Client/Curl.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
3030
protected $_host = 'localhost';
3131

3232
/**
33-
* Port
3433
* @var int
3534
*/
3635
protected $_port = 80;
@@ -60,19 +59,16 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
6059
protected $_cookies = [];
6160

6261
/**
63-
* Response headers
6462
* @var array
6563
*/
6664
protected $_responseHeaders = [];
6765

6866
/**
69-
* Response body
7067
* @var string
7168
*/
7269
protected $_responseBody = '';
7370

7471
/**
75-
* Response status
7672
* @var int
7773
*/
7874
protected $_responseStatus = 0;
@@ -282,7 +278,7 @@ public function getCookies()
282278
}
283279
$out = [];
284280
foreach ($this->_responseHeaders['Set-Cookie'] as $row) {
285-
$values = explode("; ", $row);
281+
$values = explode("; ", $row ?? '');
286282
$c = count($values);
287283
if (!$c) {
288284
continue;
@@ -309,7 +305,7 @@ public function getCookiesFull()
309305
}
310306
$out = [];
311307
foreach ($this->_responseHeaders['Set-Cookie'] as $row) {
312-
$values = explode("; ", $row);
308+
$values = explode("; ", $row ?? '');
313309
$c = count($values);
314310
if (!$c) {
315311
continue;
@@ -326,7 +322,7 @@ public function getCookiesFull()
326322
}
327323
for ($i = 0; $i < $c; $i++) {
328324
list($subkey, $val) = explode("=", $values[$i]);
329-
$out[trim($key)][trim($subkey)] = trim($val);
325+
$out[trim($key)][trim($subkey)] = $val !== null ? trim($val) : '';
330326
}
331327
}
332328
return $out;
@@ -442,6 +438,7 @@ public function doError($string)
442438
*/
443439
protected function parseHeaders($ch, $data)
444440
{
441+
$data = $data !== null ? $data : '';
445442
if ($this->_headerCount == 0) {
446443
$line = explode(" ", trim($data), 3);
447444
if (count($line) < 2) {

lib/internal/Magento/Framework/HTTP/Client/Socket.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Socket implements \Magento\Framework\HTTP\ClientInterface
2525
private $_host = 'localhost';
2626

2727
/**
28-
* Port
2928
* @var int
3029
*/
3130
private $_port = 80;
@@ -55,19 +54,16 @@ class Socket implements \Magento\Framework\HTTP\ClientInterface
5554
private $_cookies = [];
5655

5756
/**
58-
* Response headers
5957
* @var array
6058
*/
6159
private $_responseHeaders = [];
6260

6361
/**
64-
* Response body
6562
* @var string
6663
*/
6764
private $_responseBody = '';
6865

6966
/**
70-
* Response status
7167
* @var int
7268
*/
7369
private $_responseStatus = 0;
@@ -313,7 +309,7 @@ public function getCookies()
313309
}
314310
$out = [];
315311
foreach ($this->_responseHeaders['Set-Cookie'] as $row) {
316-
$values = explode("; ", $row);
312+
$values = explode("; ", $row ?? '');
317313
$c = count($values);
318314
if (!$c) {
319315
continue;
@@ -340,7 +336,7 @@ public function getCookiesFull()
340336
}
341337
$out = [];
342338
foreach ($this->_responseHeaders['Set-Cookie'] as $row) {
343-
$values = explode("; ", $row);
339+
$values = explode("; ", $row ?? '');
344340
$c = count($values);
345341
if (!$c) {
346342
continue;
@@ -357,7 +353,7 @@ public function getCookiesFull()
357353
}
358354
for ($i = 0; $i < $c; $i++) {
359355
list($subkey, $val) = explode("=", $values[$i]);
360-
$out[trim($key)][trim($subkey)] = trim($val);
356+
$out[trim($key)][trim($subkey)] = $val !== null ? trim($val) : '';
361357
}
362358
}
363359
return $out;
@@ -423,6 +419,7 @@ protected function processResponse()
423419

424420
$line = explode(" ", $responseLine, 3);
425421
if (count($line) != 3) {
422+
// phpstan:ignore "Result of method Magento\Framework\HTTP\Client\Socket::doError() (void) is used."
426423
return $this->doError("Invalid response line returned from server: " . $responseLine);
427424
}
428425
$this->_responseStatus = (int)$line[1];
@@ -438,7 +435,7 @@ protected function processResponse()
438435
*
439436
* @return void
440437
*/
441-
protected function processRedirect()
438+
protected function processRedirect() // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
442439
{
443440
// TODO: implement redirects support
444441
}
@@ -469,6 +466,7 @@ protected function makeRequest($method, $uri, $params = [])
469466
$errno = $errstr = '';
470467
$this->_sock = @fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_timeout);
471468
if (!$this->_sock) {
469+
// phpstan:ignore "Result of method Magento\Framework\HTTP\Client\Socket::doError() (void) is used."
472470
return $this->doError(sprintf("[errno: %d] %s", $errno, $errstr));
473471
}
474472

@@ -503,6 +501,7 @@ protected function makeRequest($method, $uri, $params = [])
503501
*/
504502
public function doError($string)
505503
{
504+
// phpcs:ignore Magento2.Exceptions.DirectThrow
506505
throw new \Exception($string);
507506
}
508507

@@ -532,7 +531,7 @@ protected function headersToString($append = [])
532531
* @return void
533532
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
534533
*/
535-
public function setOptions($arr)
534+
public function setOptions($arr) // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
536535
{
537536
// Stub
538537
}
@@ -545,7 +544,7 @@ public function setOptions($arr)
545544
* @return void
546545
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
547546
*/
548-
public function setOption($name, $value)
547+
public function setOption($name, $value) // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
549548
{
550549
// Stub
551550
}

lib/internal/Magento/Framework/HTTP/PhpEnvironment/Request.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Request extends \Laminas\Http\PhpEnvironment\Request
2525
/**#@+
2626
* Protocols
2727
*/
28-
const SCHEME_HTTP = 'http';
29-
const SCHEME_HTTPS = 'https';
28+
public const SCHEME_HTTP = 'http';
29+
public const SCHEME_HTTPS = 'https';
3030
/**#@-*/
3131

3232
// Configuration path for SSL Offload http header
33-
const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header';
33+
public const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header';
3434

3535
/**
3636
* @var string
@@ -48,8 +48,6 @@ class Request extends \Laminas\Http\PhpEnvironment\Request
4848
protected $action;
4949

5050
/**
51-
* PATH_INFO
52-
*
5351
* @var string
5452
*/
5553
protected $pathInfo = '';
@@ -227,7 +225,7 @@ public function getPathInfo()
227225
public function setPathInfo($pathInfo = null)
228226
{
229227
if ($pathInfo === null) {
230-
$requestUri = $this->getRequestUri();
228+
$requestUri = $this->getRequestUri() ?? '';
231229
if ('/' == $requestUri) {
232230
return $this;
233231
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ private function applyTransparency(&$imageResourceTo, $transparentIndex): void
364364
*/
365365
public function checkAlpha($fileName)
366366
{
367-
return (ord(file_get_contents($fileName, false, null, 25, 1)) & 6 & 4) == 4;
367+
return (ord(file_get_contents((string)$fileName, false, null, 25, 1)) & 6 & 4) == 4;
368368
}
369369

370370
/**
@@ -822,7 +822,7 @@ public function createPngFromString($text, $font = '')
822822
*/
823823
protected function _createImageFromText($text)
824824
{
825-
$width = imagefontwidth($this->_fontSize) * strlen($text);
825+
$width = imagefontwidth($this->_fontSize) * strlen((string)$text);
826826
$height = imagefontheight($this->_fontSize);
827827

828828
$this->_createEmptyImage($width, $height);

lib/internal/Magento/Framework/Interception/Code/InterfaceValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function __construct(ArgumentsReader $argumentsReader = null)
5050
*/
5151
public function validate($pluginClass, $interceptedType)
5252
{
53-
$interceptedType = '\\' . trim($interceptedType, '\\');
54-
$pluginClass = '\\' . trim($pluginClass, '\\');
53+
$interceptedType = '\\' . trim((string)$interceptedType, '\\');
54+
$pluginClass = '\\' . trim((string)$pluginClass, '\\');
5555
$plugin = new \ReflectionClass($pluginClass);
5656
$type = new \ReflectionClass($interceptedType);
5757

0 commit comments

Comments
 (0)