Skip to content

Commit 5450d69

Browse files
committed
Remove switch statements in favour of if
1 parent 75f44f5 commit 5450d69

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

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

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -80,45 +80,46 @@ public function validate($pluginClass, $interceptedType)
8080
);
8181
}
8282

83-
switch ($methodType) {
84-
case self::METHOD_AFTER:
85-
if (count($pluginMethodParameters) > 1) {
86-
// remove result
87-
array_shift($pluginMethodParameters);
88-
$matchedParameters = array_intersect_key($originMethodParameters, $pluginMethodParameters);
89-
$this->validateMethodsParameters(
90-
$pluginMethodParameters,
91-
$matchedParameters,
92-
$pluginClass,
93-
$pluginMethod->getName()
94-
);
95-
}
96-
break;
97-
case self::METHOD_BEFORE:
98-
$this->validateMethodsParameters(
99-
$pluginMethodParameters,
100-
$originMethodParameters,
101-
$pluginClass,
102-
$pluginMethod->getName()
103-
);
104-
break;
105-
case self::METHOD_AROUND:
106-
$proceed = array_shift($pluginMethodParameters);
107-
if (!$this->_argumentsReader->isCompatibleType($proceed['type'], '\\Closure')) {
108-
throw new ValidatorException(
109-
new Phrase(
110-
'Invalid [%1] $%2 type in %3::%4. It must be compatible with \\Closure',
111-
[$proceed['type'], $proceed['name'], $pluginClass, $pluginMethod->getName()]
112-
)
113-
);
114-
}
115-
$this->validateMethodsParameters(
116-
$pluginMethodParameters,
117-
$originMethodParameters,
118-
$pluginClass,
119-
$pluginMethod->getName()
83+
if (self::METHOD_AFTER === $methodType && count($pluginMethodParameters) > 1) {
84+
// remove result
85+
array_shift($pluginMethodParameters);
86+
$matchedParameters = array_intersect_key($originMethodParameters, $pluginMethodParameters);
87+
$this->validateMethodsParameters(
88+
$pluginMethodParameters,
89+
$matchedParameters,
90+
$pluginClass,
91+
$pluginMethod->getName()
92+
);
93+
continue;
94+
}
95+
96+
if (self::METHOD_BEFORE === $methodType) {
97+
$this->validateMethodsParameters(
98+
$pluginMethodParameters,
99+
$originMethodParameters,
100+
$pluginClass,
101+
$pluginMethod->getName()
102+
);
103+
continue;
104+
}
105+
106+
if (self::METHOD_AROUND === $methodType) {
107+
$proceed = array_shift($pluginMethodParameters);
108+
if (!$this->_argumentsReader->isCompatibleType($proceed['type'], '\\Closure')) {
109+
throw new ValidatorException(
110+
new Phrase(
111+
'Invalid [%1] $%2 type in %3::%4. It must be compatible with \\Closure',
112+
[$proceed['type'], $proceed['name'], $pluginClass, $pluginMethod->getName()]
113+
)
120114
);
121-
break;
115+
}
116+
$this->validateMethodsParameters(
117+
$pluginMethodParameters,
118+
$originMethodParameters,
119+
$pluginClass,
120+
$pluginMethod->getName()
121+
);
122+
continue;
122123
}
123124
}
124125
}
@@ -166,8 +167,7 @@ protected function validateMethodsParameters(array $pluginParameters, array $ori
166167
protected function getParametersType(\ReflectionParameter $parameter)
167168
{
168169
$parameterClass = $parameter->getClass();
169-
$type = $parameterClass ? '\\' . $parameterClass->getName() : ($parameter->isArray() ? 'array' : null);
170-
return $type;
170+
return $parameterClass ? '\\' . $parameterClass->getName() : ($parameter->isArray() ? 'array' : null);
171171
}
172172

173173
/**
@@ -179,17 +179,16 @@ protected function getParametersType(\ReflectionParameter $parameter)
179179
*/
180180
protected function getOriginMethodName($pluginMethodName)
181181
{
182-
switch ($this->getMethodType($pluginMethodName)) {
183-
case self::METHOD_AFTER:
184-
return lcfirst(substr($pluginMethodName, 5));
185-
186-
case self::METHOD_BEFORE:
187-
case self::METHOD_AROUND:
188-
return lcfirst(substr($pluginMethodName, 6));
182+
$methodType = $this->getMethodType($pluginMethodName);
189183

190-
default:
191-
return null;
184+
if (self::METHOD_AFTER === $methodType) {
185+
return lcfirst(substr($pluginMethodName, 5));
192186
}
187+
if (self::METHOD_BEFORE === $methodType || self::METHOD_AROUND === $methodType) {
188+
return lcfirst(substr($pluginMethodName, 6));
189+
}
190+
191+
return null;
193192
}
194193

195194
/**

0 commit comments

Comments
 (0)