Skip to content

Commit 7bab557

Browse files
author
Oleksii Korshenko
committed
MAGETWO-52616: Bug Fixes Contribution
- fixed code style
1 parent 3afb568 commit 7bab557

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,10 @@ public function getGetterReturnType($methodReflection)
322322
if (preg_match("/.*\\@return\\s+({$escapedReturnType}).*/i", $methodDocBlock->getContents(), $matches)) {
323323
$returnType = $matches[1];
324324
}
325-
$isRequired = preg_match("/.*\@return\s+\S+\|null.*/i", $methodDocBlock->getContents(), $matches)
326-
? false
327-
: true;
325+
$isNotRequired = (bool)preg_match("/.*\@return\s+\S+\|null.*/i", $methodDocBlock->getContents(), $matches);
328326
return [
329327
'type' => $returnType,
330-
'isRequired' => $isRequired,
328+
'isRequired' => !$isNotRequired,
331329
'description' => $returnAnnotation->getDescription(),
332330
'parameterCount' => $methodReflection->getNumberOfRequiredParameters()
333331
];
@@ -385,13 +383,8 @@ public function normalizeType($type)
385383
*/
386384
public function isTypeSimple($type)
387385
{
388-
$type = $this->normalizeType($type);
389-
if ($this->isArrayType($type)) {
390-
$type = $this->getArrayItemType($type);
391-
}
392-
393386
return in_array(
394-
$type,
387+
$this->getNormalizedType($type),
395388
[
396389
self::NORMALIZED_STRING_TYPE,
397390
self::NORMALIZED_INT_TYPE,
@@ -410,12 +403,7 @@ public function isTypeSimple($type)
410403
*/
411404
public function isTypeAny($type)
412405
{
413-
$type = $this->normalizeType($type);
414-
if ($this->isArrayType($type)) {
415-
$type = $this->getArrayItemType($type);
416-
}
417-
418-
return ($type == self::NORMALIZED_ANY_TYPE);
406+
return ($this->getNormalizedType($type) == self::NORMALIZED_ANY_TYPE);
419407
}
420408

421409
/**
@@ -623,11 +611,13 @@ protected function setType(&$value, $type)
623611
{
624612
// settype doesn't work for boolean string values.
625613
// ex: custom_attributes passed from SOAP client can have boolean values as string
626-
if ($type == 'bool' || $type == 'boolean') {
614+
$booleanTypes = ['bool', 'boolean'];
615+
if (in_array($type, $booleanTypes)) {
627616
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
628617
return true;
629618
}
630-
if (($type == 'int' || $type == 'float') && !is_numeric($value)) {
619+
$numType = ['int', 'float'];
620+
if (in_array($type, $numType) && !is_numeric($value)) {
631621
return false;
632622
}
633623
return settype($value, $type);
@@ -731,4 +721,19 @@ public function getOperationName($serviceName, $methodName)
731721
{
732722
return $serviceName . ucfirst($methodName);
733723
}
724+
725+
/**
726+
* Get normalized type
727+
*
728+
* @param string $type
729+
* @return string
730+
*/
731+
private function getNormalizedType($type)
732+
{
733+
$type = $this->normalizeType($type);
734+
if ($this->isArrayType($type)) {
735+
$type = $this->getArrayItemType($type);
736+
}
737+
return $type;
738+
}
734739
}

0 commit comments

Comments
 (0)