Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 52cec2d

Browse files
committed
Some CS fixes in Zend_Rest_Server
1 parent 3f7b1c9 commit 52cec2d

File tree

1 file changed

+91
-37
lines changed

1 file changed

+91
-37
lines changed

library/Zend/Rest/Server.php

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,28 @@ public function handle($request = false)
182182
if (isset($request['method'])) {
183183
$this->_method = $request['method'];
184184
if (isset($this->_functions[$this->_method])) {
185-
if ($this->_functions[$this->_method] instanceof Zend_Server_Reflection_Function || $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method && $this->_functions[$this->_method]->isPublic()) {
186-
$request_keys = array_keys($request);
187-
array_walk($request_keys, array(__CLASS__, "lowerCase"));
188-
$request = array_combine($request_keys, $request);
189-
190-
$func_args = $this->_functions[$this->_method]->getParameters();
185+
if ($this->_functions[$this->_method] instanceof
186+
Zend_Server_Reflection_Function
187+
|| $this->_functions[$this->_method] instanceof
188+
Zend_Server_Reflection_Method
189+
&& $this->_functions[$this->_method]->isPublic()
190+
) {
191+
$requestKeys = array_keys($request);
192+
array_walk($requestKeys, array(__CLASS__, "lowerCase"));
193+
$request = array_combine($requestKeys, $request);
194+
195+
$funcArgs = $this->_functions[$this->_method]->getParameters();
191196

192197
// calling_args will be a zero-based array of the parameters
193-
$calling_args = array();
194-
$missing_args = array();
195-
foreach ($func_args as $i => $arg) {
198+
$callingArgs = array();
199+
$missingArgs = array();
200+
foreach ($funcArgs as $i => $arg) {
196201
if (isset($request[strtolower($arg->getName())])) {
197-
$calling_args[$i] = $request[strtolower($arg->getName())];
202+
$callingArgs[$i] = $request[strtolower($arg->getName())];
198203
} elseif ($arg->isOptional()) {
199-
$calling_args[$i] = $arg->getDefaultValue();
204+
$callingArgs[$i] = $arg->getDefaultValue();
200205
} else {
201-
$missing_args[] = $arg->getName();
206+
$missingArgs[] = $arg->getName();
202207
}
203208
}
204209

@@ -207,57 +212,79 @@ public function handle($request = false)
207212
if (substr($key, 0, 3) == 'arg') {
208213
$key = str_replace('arg', '', $key);
209214
$anonymousArgs[$key] = $value;
210-
if (($index = array_search($key, $missing_args)) !== false) {
211-
unset($missing_args[$index]);
215+
if (($index = array_search($key, $missingArgs)) !== false) {
216+
unset($missingArgs[$index]);
212217
}
213218
}
214219
}
215220

216221
// re-key the $anonymousArgs to be zero-based, and add in
217222
// any values already set in calling_args (optional defaults)
218223
ksort($anonymousArgs);
219-
$calling_args = array_values($anonymousArgs) + $calling_args;
224+
$callingArgs = array_values($anonymousArgs) + $callingArgs;
220225

221226
// Sort arguments by key -- @see ZF-2279
222-
ksort($calling_args);
227+
ksort($callingArgs);
223228

224229
$result = false;
225-
if (count($calling_args) < count($func_args)) {
230+
if (count($callingArgs) < count($funcArgs)) {
226231
require_once 'Zend/Rest/Server/Exception.php';
227-
$result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Missing argument(s): ' . implode(', ', $missing_args) . '.'), 400);
232+
$result = $this->fault(
233+
new Zend_Rest_Server_Exception(
234+
'Invalid Method Call to ' . $this->_method
235+
. '. Missing argument(s): ' . implode(
236+
', ', $missingArgs
237+
) . '.'
238+
), 400
239+
);
228240
}
229241

230-
if (!$result && $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method) {
242+
if (!$result && $this->_functions[$this->_method] instanceof
243+
Zend_Server_Reflection_Method
244+
) {
231245
// Get class
232246
$class = $this->_functions[$this->_method]->getDeclaringClass()->getName();
233247

234248
if ($this->_functions[$this->_method]->isStatic()) {
235249
// for some reason, invokeArgs() does not work the same as
236250
// invoke(), and expects the first argument to be an object.
237251
// So, using a callback if the method is static.
238-
$result = $this->_callStaticMethod($class, $calling_args);
252+
$result = $this->_callStaticMethod(
253+
$class,
254+
$callingArgs
255+
);
239256
} else {
240257
// Object method
241-
$result = $this->_callObjectMethod($class, $calling_args);
258+
$result = $this->_callObjectMethod(
259+
$class,
260+
$callingArgs
261+
);
242262
}
243263
} elseif (!$result) {
244264
try {
245-
$result = call_user_func_array($this->_functions[$this->_method]->getName(), $calling_args); //$this->_functions[$this->_method]->invokeArgs($calling_args);
265+
$result = call_user_func_array(
266+
$this->_functions[$this->_method]->getName(),
267+
$callingArgs
268+
);
246269
} catch (Exception $e) {
247270
$result = $this->fault($e);
248271
}
249272
}
250273
} else {
251274
require_once "Zend/Rest/Server/Exception.php";
252275
$result = $this->fault(
253-
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
276+
new Zend_Rest_Server_Exception(
277+
"Unknown Method '$this->_method'."
278+
),
254279
404
255280
);
256281
}
257282
} else {
258283
require_once "Zend/Rest/Server/Exception.php";
259284
$result = $this->fault(
260-
new Zend_Rest_Server_Exception("Unknown Method '$this->_method'."),
285+
new Zend_Rest_Server_Exception(
286+
"Unknown Method '$this->_method'."
287+
),
261288
404
262289
);
263290
}
@@ -362,9 +389,11 @@ protected function _handleStruct($struct)
362389
* @param DOMElement $parent
363390
* @return void
364391
*/
365-
protected function _structValue($struct, DOMDocument $dom, DOMElement $parent)
392+
protected function _structValue(
393+
$struct, DOMDocument $dom, DOMElement $parent
394+
)
366395
{
367-
$struct = (array) $struct;
396+
$struct = (array)$struct;
368397

369398
foreach ($struct as $key => $value) {
370399
if ($value === false) {
@@ -373,7 +402,7 @@ protected function _structValue($struct, DOMDocument $dom, DOMElement $parent)
373402
$value = 1;
374403
}
375404

376-
if (ctype_digit((string) $key)) {
405+
if (ctype_digit((string)$key)) {
377406
$key = 'key_' . $key;
378407
}
379408

@@ -487,13 +516,23 @@ public function fault($exception = null, $code = null)
487516

488517
if ($exception instanceof Exception) {
489518
$element = $dom->createElement('message');
490-
$element->appendChild($dom->createTextNode($exception->getMessage()));
519+
$element->appendChild(
520+
$dom->createTextNode($exception->getMessage())
521+
);
491522
$xmlResponse->appendChild($element);
492523
$code = $exception->getCode();
493524
} elseif (($exception !== null) || 'rest' == $function) {
494-
$xmlResponse->appendChild($dom->createElement('message', 'An unknown error occured. Please try again.'));
525+
$xmlResponse->appendChild(
526+
$dom->createElement(
527+
'message', 'An unknown error occured. Please try again.'
528+
)
529+
);
495530
} else {
496-
$xmlResponse->appendChild($dom->createElement('message', 'Call to ' . $method . ' failed.'));
531+
$xmlResponse->appendChild(
532+
$dom->createElement(
533+
'message', 'Call to ' . $method . ' failed.'
534+
)
535+
);
497536
}
498537

499538
$xmlMethod->appendChild($xmlResponse);
@@ -536,7 +575,9 @@ public function addFunction($function, $namespace = '')
536575
$this->_functions[$func] = $this->_reflection->reflectFunction($func);
537576
} else {
538577
require_once 'Zend/Rest/Server/Exception.php';
539-
throw new Zend_Rest_Server_Exception("Invalid Method Added to Service.");
578+
throw new Zend_Rest_Server_Exception(
579+
"Invalid Method Added to Service."
580+
);
540581
}
541582
}
542583
}
@@ -581,7 +622,13 @@ public function setPersistence($mode)
581622
protected function _callStaticMethod($class, array $args)
582623
{
583624
try {
584-
$result = call_user_func_array(array($class, $this->_functions[$this->_method]->getName()), $args);
625+
$result = call_user_func_array(
626+
array(
627+
$class,
628+
$this->_functions[$this->_method]->getName()
629+
),
630+
$args
631+
);
585632
} catch (Exception $e) {
586633
$result = $this->fault($e);
587634
}
@@ -606,14 +653,21 @@ protected function _callObjectMethod($class, array $args)
606653
}
607654
} catch (Exception $e) {
608655
require_once 'Zend/Rest/Server/Exception.php';
609-
throw new Zend_Rest_Server_Exception('Error instantiating class ' . $class .
610-
' to invoke method ' . $this->_functions[$this->_method]->getName() .
611-
' (' . $e->getMessage() . ') ',
612-
500, $e);
656+
throw new Zend_Rest_Server_Exception(
657+
'Error instantiating class ' . $class .
658+
' to invoke method '
659+
. $this->_functions[$this->_method]->getName() .
660+
' (' . $e->getMessage() . ') ',
661+
500,
662+
$e
663+
);
613664
}
614665

615666
try {
616-
$result = $this->_functions[$this->_method]->invokeArgs($object, $args);
667+
$result = $this->_functions[$this->_method]->invokeArgs(
668+
$object,
669+
$args
670+
);
617671
} catch (Exception $e) {
618672
$result = $this->fault($e);
619673
}

0 commit comments

Comments
 (0)