Skip to content

Commit 73a75d1

Browse files
anzinandrewbess
authored andcommitted
AC-3161: fixed logic affected by "RFC: Deprecate passing null"
1 parent b53582a commit 73a75d1

File tree

14 files changed

+67
-70
lines changed

14 files changed

+67
-70
lines changed

app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ protected function generatePathInfo(string $methodName, array $httpMethodData, s
233233
{
234234
$methodData = $httpMethodData[Converter::KEY_METHOD];
235235
$uri = ucwords(str_replace(['/{', '}/', '{', '}'], '/', $uri), "/");
236-
237-
$operationId = ucfirst($methodName).str_replace(['/', '-'], '', $uri);
236+
237+
$operationId = ucfirst($methodName) . str_replace(['/', '-'], '', $uri);
238238
$pathInfo = [
239239
'tags' => [$tagName],
240240
'description' => $methodData['documentation'],
@@ -327,7 +327,7 @@ private function generateMethodParameters($httpMethodData, $operationId)
327327
if (!isset($parameterInfo['type'])) {
328328
return [];
329329
}
330-
$description = isset($parameterInfo['documentation']) ? $parameterInfo['documentation'] : null;
330+
$description = $parameterInfo['documentation'] ?? null;
331331

332332
/** Get location of parameter */
333333
if (strpos($httpMethodData['uri'], (string) ('{' . $parameterName . '}')) !== false) {
@@ -432,11 +432,11 @@ protected function getObjectSchema($typeName, $description = '')
432432
if (!empty($description)) {
433433
$result['description'] = $description;
434434
}
435-
$trimedTypeName = rtrim($typeName, '[]');
435+
$trimedTypeName = $typeName !== null ? rtrim($typeName, '[]') : '';
436436
if ($simpleType = $this->getSimpleType($trimedTypeName)) {
437437
$result['items'] = ['type' => $simpleType];
438438
} else {
439-
if (strpos($typeName, '[]') !== false) {
439+
if ($typeName && strpos($typeName, '[]') !== false) {
440440
$result['items'] = ['$ref' => $this->getDefinitionReference($trimedTypeName)];
441441
} else {
442442
$result = ['$ref' => $this->getDefinitionReference($trimedTypeName)];
@@ -708,14 +708,14 @@ protected function getQueryParamNames($name, $type, $description, $prefix = '')
708708
// Primitive type or array of primitive types
709709
return [
710710
$this->handlePrimitive($name, $prefix) => [
711-
'type' => substr($type, -2) === '[]' ? $type : $this->getSimpleType($type),
711+
'type' => ($type && substr($type, -2) === '[]') ? $type : $this->getSimpleType($type),
712712
'description' => $description
713713
]
714714
];
715715
}
716716
if ($this->typeProcessor->isArrayType($type)) {
717717
// Array of complex type
718-
$arrayType = substr($type, 0, -2);
718+
$arrayType = $type !== null ? substr($type, 0, -2) : '';
719719
return $this->handleComplex($name, $arrayType, $prefix, true);
720720
} else {
721721
// Complex type
@@ -739,9 +739,7 @@ private function handleComplex($name, $type, $prefix, $isArray)
739739
$queryNames = [];
740740
foreach ($parameters as $subParameterName => $subParameterInfo) {
741741
$subParameterType = $subParameterInfo['type'];
742-
$subParameterDescription = isset($subParameterInfo['documentation'])
743-
? $subParameterInfo['documentation']
744-
: null;
742+
$subParameterDescription = $subParameterInfo['documentation'] ?? null;
745743
$subPrefix = $prefix
746744
? $prefix . '[' . $name . ']'
747745
: $name;
@@ -784,8 +782,8 @@ private function convertPathParams($uri)
784782
$parts = explode('/', $uri);
785783
$count = count($parts);
786784
for ($i=0; $i < $count; $i++) {
787-
if (strpos($parts[$i], ':') === 0) {
788-
$parts[$i] = '{' . substr($parts[$i], 1) . '}';
785+
if (strpos($parts[$i] ?? '', ':') === 0) {
786+
$parts[$i] = '{' . substr($parts[$i] ?? '', 1) . '}';
789787
}
790788
}
791789
return implode('/', $parts);

app/code/Magento/Webapi/Model/ServiceMetadata.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ServiceMetadata
6969
protected $cache;
7070

7171
/**
72-
* @var \Magento\Webapi\Model\Config
72+
* @var Config
7373
*/
7474
protected $config;
7575

@@ -220,7 +220,7 @@ public function getServiceMetadata($serviceName)
220220
*/
221221
public function getServiceName($interfaceName, $version, $preserveVersion = true)
222222
{
223-
if (!preg_match(\Magento\Webapi\Model\Config::SERVICE_CLASS_PATTERN, $interfaceName, $matches)) {
223+
if ($interfaceName && !preg_match(Config::SERVICE_CLASS_PATTERN, $interfaceName, $matches)) {
224224
$apiClassPattern = "#^(.+?)\\\\(.+?)\\\\Api\\\\(.+?)(Interface)?$#";
225225
preg_match($apiClassPattern, $interfaceName, $matches);
226226
}
@@ -232,7 +232,7 @@ public function getServiceName($interfaceName, $version, $preserveVersion = true
232232
if ($matches[4] === 'Interface') {
233233
$matches[4] = $matches[3];
234234
}
235-
$serviceNameParts = explode('\\', trim($matches[4], '\\'));
235+
$serviceNameParts = explode('\\', trim($matches[4] ?? '', '\\'));
236236
if ($moduleName == $serviceNameParts[0]) {
237237
/** Avoid duplication of words in service name */
238238
$moduleName = '';
@@ -242,11 +242,11 @@ public function getServiceName($interfaceName, $version, $preserveVersion = true
242242
if ($preserveVersion) {
243243
$serviceNameParts[] = $version;
244244
}
245-
} elseif (preg_match(\Magento\Webapi\Model\Config::API_PATTERN, $interfaceName, $matches)) {
245+
} elseif ($interfaceName && preg_match(Config::API_PATTERN, $interfaceName, $matches)) {
246246
$moduleNamespace = $matches[1];
247247
$moduleName = $matches[2];
248248
$moduleNamespace = ($moduleNamespace == 'Magento') ? '' : $moduleNamespace;
249-
$serviceNameParts = explode('\\', trim($matches[3], '\\'));
249+
$serviceNameParts = explode('\\', trim($matches[3] ?? '', '\\'));
250250
if ($moduleName == $serviceNameParts[0]) {
251251
/** Avoid duplication of words in service name */
252252
$moduleName = '';

app/code/Magento/Webapi/Model/Soap/Wsdl/ComplexTypeStrategy.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function addAnnotation(\DOMElement $element, $documentation, $default = n
247247
$this->_processDocInstructions($appInfoNode, $tagValue);
248248
break;
249249
default:
250-
$nodeValue = trim($tagValue);
250+
$nodeValue = $tagValue !== null ? trim($tagValue) : '';
251251
$simpleTextNode = $this->_getDom()->createElement(self::APP_INF_NS . ':' . $tagName);
252252
$simpleTextNode->appendChild($this->_getDom()->createTextNode($nodeValue));
253253
$appInfoNode->appendChild($simpleTextNode);
@@ -336,7 +336,7 @@ protected function _getElementType(\DOMElement $element)
336336
*/
337337
protected function _processRequiredAnnotation($annotation, $documentation, \DOMElement $appInfoNode)
338338
{
339-
if (!preg_match("/{{$annotation}:.+}/Ui", $documentation)) {
339+
if (!$documentation || !preg_match("/{{$annotation}:.+}/Ui", $documentation)) {
340340
$annotationNode = $this->_getDom()->createElement(self::APP_INF_NS . ':' . $annotation);
341341
$appInfoNode->appendChild($annotationNode);
342342
}
@@ -384,7 +384,7 @@ protected function _processCallInfo(\DOMElement $appInfoNode, $callInfo)
384384
*/
385385
protected function _processDocInstructions(\DOMElement $appInfoNode, $tagValue)
386386
{
387-
if (preg_match('/(input|output):(.+)/', $tagValue, $docMatches)) {
387+
if ($tagValue && preg_match('/(input|output):(.+)/', $tagValue, $docMatches)) {
388388
$docInstructionsNode = $this->_getDom()->createElement(self::APP_INF_NS . ':docInstructions');
389389
$directionNode = $this->_getDom()->createElement(self::APP_INF_NS . ':' . $docMatches[1]);
390390
$directionValueNode = $this->_getDom()->createElement(self::APP_INF_NS . ':' . $docMatches[2]);
@@ -403,7 +403,7 @@ protected function _processDocInstructions(\DOMElement $appInfoNode, $tagValue)
403403
*/
404404
protected function _processSeeLink(\DOMElement $appInfoNode, $tagValue)
405405
{
406-
if (preg_match('|([http://]?.+):(.+):(.+)|i', $tagValue, $matches)) {
406+
if ($tagValue && preg_match('|([http://]?.+):(.+):(.+)|i', $tagValue, $matches)) {
407407
$seeLink = ['url' => $matches[1], 'title' => $matches[2], 'for' => $matches[3]];
408408
$seeLinkNode = $this->_getDom()->createElement(self::APP_INF_NS . ':seeLink');
409409
foreach (['url', 'title', 'for'] as $subNodeName) {
@@ -453,8 +453,8 @@ private function processCallInfo(array &$callInfo, string $tagValue): void
453453
$callInfoRegExp = '/([a-z].+):(returned|requiredInput):(yes|no|always|conditionally)/i';
454454
if (preg_match($callInfoRegExp, $tagValue)) {
455455
list($callName, $direction, $condition) = explode(':', $tagValue);
456-
$condition = strtolower($condition);
457-
if (preg_match('/allCallsExcept\(([a-zA-Z].+)\)/', $callName, $calls)) {
456+
$condition = $condition !== null ? strtolower($condition) : '';
457+
if ($callName && preg_match('/allCallsExcept\(([a-zA-Z].+)\)/', $callName, $calls)) {
458458
$callInfo[$direction][$condition] = [
459459
'allCallsExcept' => $calls[1],
460460
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function generateTopicNameFromService($serviceInterface, $serviceMethod,
179179
*/
180180
private function generateKey($typeName, $methodName, $delimiter = '\\', $lcfirst = true)
181181
{
182-
$parts = explode($delimiter, trim($typeName, $delimiter));
182+
$parts = explode($delimiter, trim($typeName ?: '', $delimiter));
183183
foreach ($parts as &$part) {
184184
$part = ltrim($part, ':');
185185
if ($lcfirst === true) {

app/code/Magento/WebapiAsync/Plugin/Rest/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ public function afterGetRestRoutes(RestConfig $restConfig, array $routes, Reques
8181
*/
8282
private function canProcess(Request $request): bool
8383
{
84-
return preg_match(self::ASYNC_PROCESSOR_PATH, $request->getUri()->getPath()) === 1;
84+
return preg_match(self::ASYNC_PROCESSOR_PATH, $request->getUri()->getPath() ?? '') === 1;
8585
}
8686
}

app/code/Magento/Weee/Observer/UpdateProductOptionsObserver.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
class UpdateProductOptionsObserver implements ObserverInterface
1111
{
1212
/**
13-
* Weee data
14-
*
1513
* @var \Magento\Weee\Helper\Data
1614
*/
1715
protected $weeeData = null;
@@ -22,8 +20,6 @@ class UpdateProductOptionsObserver implements ObserverInterface
2220
protected $registry;
2321

2422
/**
25-
* Tax data
26-
*
2723
* @var \Magento\Tax\Helper\Data
2824
*/
2925
protected $taxData;
@@ -81,7 +77,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
8177
// we need to display the individual Weee amounts
8278
foreach ($this->weeeData->getWeeeAttributesForBundle($product) as $weeeAttributes) {
8379
foreach ($weeeAttributes as $weeeAttribute) {
84-
if (!preg_match('/' . $weeeAttribute->getCode() . '/', $options['optionTemplate'])) {
80+
if (!preg_match('/' . $weeeAttribute->getCode() . '/', $options['optionTemplate'] ?? '')) {
8581
$options['optionTemplate'] .= sprintf(
8682
' <%% if (data.weeePrice' . $weeeAttribute->getCode() . ') { %%>'
8783
. ' (' . $weeeAttribute->getName()

app/code/Magento/Widget/Block/Adminhtml/Widget/Options.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected function _addField($parameter)
193193
// hidden element
194194
if (!$parameter->getVisible()) {
195195
$fieldType = 'hidden';
196-
// just an element renderer
196+
// just an element renderer
197197
} elseif ($fieldType && $this->_isClassName($fieldType)) {
198198
$fieldRenderer = $this->getLayout()->createBlock($fieldType);
199199
$fieldType = $this->_defaultElementType;
@@ -244,6 +244,6 @@ protected function _addField($parameter)
244244
*/
245245
protected function _isClassName($fieldType)
246246
{
247-
return preg_match('/[A-Z]/', $fieldType) > 0;
247+
return $fieldType && preg_match('/[A-Z]/', $fieldType) > 0;
248248
}
249249
}

app/code/Magento/Widget/Model/Config/Converter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
class Converter implements \Magento\Framework\Config\ConverterInterface
99
{
1010
/**
11-
* {@inheritdoc}
11+
* @inheritdoc
12+
*
1213
* @SuppressWarnings(PHPMD.NPathComplexity)
1314
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
15+
* phpcs:disable Generic.Metrics.NestingLevel
1416
*/
1517
public function convert($source)
1618
{
@@ -60,15 +62,15 @@ public function convert($source)
6062
if ($container->nodeName === '#text' || $container->nodeName === '#comment') {
6163
continue;
6264
}
65+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
6366
$widgetArray['supported_containers'] = array_merge(
6467
$widgetArray['supported_containers'],
6568
$this->_convertContainer($container)
6669
);
6770
}
6871
break;
69-
case "#text":
70-
break;
7172
case '#comment':
73+
case "#text":
7274
break;
7375
default:
7476
throw new \LogicException(
@@ -240,7 +242,7 @@ protected function _convertDepends($source)
240242
];
241243

242244
continue;
243-
} else if (!isset($depends[$dependencyName]['values'])) {
245+
} elseif (!isset($depends[$dependencyName]['values'])) {
244246
$depends[$dependencyName]['values'] = [$depends[$dependencyName]['value']];
245247
unset($depends[$dependencyName]['value']);
246248
}
@@ -292,7 +294,7 @@ protected function _convertData($source)
292294
if ($dataChild instanceof \DOMElement) {
293295
$data[$dataChild->attributes->getNamedItem('name')->nodeValue] = $this->_convertData($dataChild);
294296
} else {
295-
if (strlen(trim($dataChild->nodeValue))) {
297+
if ($dataChild->nodeValue && strlen(trim($dataChild->nodeValue))) {
296298
$data = $dataChild->nodeValue;
297299
}
298300
}

app/code/Magento/Widget/Model/Widget/Instance.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@
3333
*/
3434
class Instance extends \Magento\Framework\Model\AbstractModel
3535
{
36-
const SPECIFIC_ENTITIES = 'specific';
36+
public const SPECIFIC_ENTITIES = 'specific';
3737

38-
const ALL_ENTITIES = 'all';
38+
public const ALL_ENTITIES = 'all';
3939

40-
const DEFAULT_LAYOUT_HANDLE = 'default';
40+
public const DEFAULT_LAYOUT_HANDLE = 'default';
4141

42-
const PRODUCT_LAYOUT_HANDLE = 'catalog_product_view';
42+
public const PRODUCT_LAYOUT_HANDLE = 'catalog_product_view';
4343

4444
/**
4545
* @deprecated see self::SINGLE_PRODUCT_LAYOUT_HANDLE
4646
*/
47-
const SINGLE_PRODUCT_LAYOUT_HANLDE = self::SINGLE_PRODUCT_LAYOUT_HANDLE;
47+
public const SINGLE_PRODUCT_LAYOUT_HANLDE = self::SINGLE_PRODUCT_LAYOUT_HANDLE;
4848

49-
const SINGLE_PRODUCT_LAYOUT_HANDLE = 'catalog_product_view_id_{{ID}}';
49+
public const SINGLE_PRODUCT_LAYOUT_HANDLE = 'catalog_product_view_id_{{ID}}';
5050

51-
const PRODUCT_TYPE_LAYOUT_HANDLE = 'catalog_product_view_type_{{TYPE}}';
51+
public const PRODUCT_TYPE_LAYOUT_HANDLE = 'catalog_product_view_type_{{TYPE}}';
5252

53-
const ANCHOR_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_type_layered';
53+
public const ANCHOR_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_type_layered';
5454

55-
const NOTANCHOR_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_type_default';
55+
public const NOTANCHOR_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_type_default';
5656

57-
const SINGLE_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_id_{{ID}}';
57+
public const SINGLE_CATEGORY_LAYOUT_HANDLE = 'catalog_category_view_id_{{ID}}';
5858

5959
/**
6060
* @var array
@@ -268,7 +268,7 @@ public function beforeSave()
268268
];
269269
if ($pageGroupData['for'] == self::SPECIFIC_ENTITIES) {
270270
$layoutHandleUpdates = [];
271-
foreach (explode(',', $pageGroupData['entities']) as $entity) {
271+
foreach (explode(',', $pageGroupData['entities'] ?? '') as $entity) {
272272
$layoutHandleUpdates[] = str_replace(
273273
'{{ID}}',
274274
$entity,

app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Wishlist\Controller\Index;
99

10+
use Magento\Catalog\Model\Product\Type\AbstractType;
1011
use Magento\Framework\App\Action;
1112
use Magento\Framework\App\Action\HttpGetActionInterface;
1213
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -69,9 +70,9 @@ public function execute()
6970
}
7071

7172
$optionId = null;
72-
if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
73+
if ($option->getCode() && strpos($option->getCode(), AbstractType::OPTION_PREFIX) === 0) {
7374
$optionId = str_replace(
74-
\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX,
75+
AbstractType::OPTION_PREFIX,
7576
'',
7677
$option->getCode()
7778
);
@@ -107,5 +108,7 @@ public function execute()
107108
$resultForward->forward('noroute');
108109
return $resultForward;
109110
}
111+
112+
return $resultForward;
110113
}
111114
}

0 commit comments

Comments
 (0)