@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | // exception and creates a response. If no response is created, it is |
94 | 94 | // assumed that theres no middleware who can handle it and the error is |
95 | 95 | // thrown again |
96 | - } catch(\Exception $exception){ |
|
96 | + } catch (\Exception $exception) { |
|
97 | 97 | $response = $this->middlewareDispatcher->afterException( |
98 | 98 | $controller, $methodName, $exception); |
99 | 99 | if (is_null($response)) { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | // valid types that will be casted |
132 | 132 | $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
133 | 133 | |
134 | - foreach($this->reflector->getParameters() as $param => $default) { |
|
134 | + foreach ($this->reflector->getParameters() as $param => $default) { |
|
135 | 135 | |
136 | 136 | // try to get the parameter from the request object and cast |
137 | 137 | // it to the type annotated in the @param annotation |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | // if this is submitted using GET or a POST form, 'false' should be |
142 | 142 | // converted to false |
143 | - if(($type === 'bool' || $type === 'boolean') && |
|
143 | + if (($type === 'bool' || $type === 'boolean') && |
|
144 | 144 | $value === 'false' && |
145 | 145 | ( |
146 | 146 | $this->request->method === 'GET' || |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ) { |
151 | 151 | $value = false; |
152 | 152 | |
153 | - } elseif($value !== null && in_array($type, $types)) { |
|
153 | + } elseif ($value !== null && in_array($type, $types)) { |
|
154 | 154 | settype($value, $type); |
155 | 155 | } |
156 | 156 | |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | $response = call_user_func_array(array($controller, $methodName), $arguments); |
161 | 161 | |
162 | 162 | // format response |
163 | - if($response instanceof DataResponse || !($response instanceof Response)) { |
|
163 | + if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
164 | 164 | |
165 | 165 | // get format from the url format or request format parameter |
166 | 166 | $format = $this->request->getParam('format'); |
167 | 167 | |
168 | 168 | // if none is given try the first Accept header |
169 | - if($format === null) { |
|
169 | + if ($format === null) { |
|
170 | 170 | $headers = $this->request->getHeader('Accept'); |
171 | 171 | $format = $controller->getResponderByHTTPHeader($headers, null); |
172 | 172 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param array $server $_SERVER |
42 | 42 | * @param string $protocolVersion the http version to use defaults to HTTP/1.1 |
43 | 43 | */ |
44 | - public function __construct($server, $protocolVersion='HTTP/1.1') { |
|
44 | + public function __construct($server, $protocolVersion = 'HTTP/1.1') { |
|
45 | 45 | $this->server = $server; |
46 | 46 | $this->protocolVersion = $protocolVersion; |
47 | 47 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | * @param string $ETag the etag |
117 | 117 | * @return string |
118 | 118 | */ |
119 | - public function getStatusHeader($status, \DateTime $lastModified=null, |
|
120 | - $ETag=null) { |
|
119 | + public function getStatusHeader($status, \DateTime $lastModified = null, |
|
120 | + $ETag = null) { |
|
121 | 121 | |
122 | - if(!is_null($lastModified)) { |
|
122 | + if (!is_null($lastModified)) { |
|
123 | 123 | $lastModified = $lastModified->format(\DateTime::RFC2822); |
124 | 124 | } |
125 | 125 | |
126 | 126 | // if etag or lastmodified have not changed, return a not modified |
127 | 127 | if ((isset($this->server['HTTP_IF_NONE_MATCH']) |
128 | - && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string)$ETag) |
|
128 | + && trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string) $ETag) |
|
129 | 129 | |
130 | 130 | || |
131 | 131 | |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | // we have one change currently for the http 1.0 header that differs |
140 | 140 | // from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND |
141 | 141 | // if this differs any more, we want to create childclasses for this |
142 | - if($status === self::STATUS_TEMPORARY_REDIRECT |
|
142 | + if ($status === self::STATUS_TEMPORARY_REDIRECT |
|
143 | 143 | && $this->protocolVersion === 'HTTP/1.0') { |
144 | 144 | |
145 | 145 | $status = self::STATUS_FOUND; |
146 | 146 | } |
147 | 147 | |
148 | - return $this->protocolVersion . ' ' . $status . ' ' . |
|
148 | + return $this->protocolVersion.' '.$status.' '. |
|
149 | 149 | $this->headers[$status]; |
150 | 150 | } |
151 | 151 |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @throws SecurityException |
81 | 81 | * @since 6.0.0 |
82 | 82 | */ |
83 | - public function beforeController($controller, $methodName){ |
|
83 | + public function beforeController($controller, $methodName) { |
|
84 | 84 | // ensure that @CORS annotated API routes are not used in conjunction |
85 | 85 | // with session authentication since this enables CSRF attack vectors |
86 | 86 | if ($this->reflector->hasAnnotation('CORS') && |
87 | - !$this->reflector->hasAnnotation('PublicPage')) { |
|
87 | + !$this->reflector->hasAnnotation('PublicPage')) { |
|
88 | 88 | $user = $this->request->server['PHP_AUTH_USER']; |
89 | 89 | $pass = $this->request->server['PHP_AUTH_PW']; |
90 | 90 | |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | * @return Response a Response object |
111 | 111 | * @throws SecurityException |
112 | 112 | */ |
113 | - public function afterController($controller, $methodName, Response $response){ |
|
113 | + public function afterController($controller, $methodName, Response $response) { |
|
114 | 114 | // only react if its a CORS request and if the request sends origin and |
115 | 115 | |
116 | - if(isset($this->request->server['HTTP_ORIGIN']) && |
|
116 | + if (isset($this->request->server['HTTP_ORIGIN']) && |
|
117 | 117 | $this->reflector->hasAnnotation('CORS')) { |
118 | 118 | |
119 | 119 | // allow credentials headers must not be true or CSRF is possible |
120 | 120 | // otherwise |
121 | - foreach($response->getHeaders() as $header => $value) { |
|
122 | - if(strtolower($header) === 'access-control-allow-credentials' && |
|
121 | + foreach ($response->getHeaders() as $header => $value) { |
|
122 | + if (strtolower($header) === 'access-control-allow-credentials' && |
|
123 | 123 | strtolower(trim($value)) === 'true') { |
124 | 124 | $msg = 'Access-Control-Allow-Credentials must not be '. |
125 | 125 | 'set to true in order to prevent CSRF'; |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | * @throws \Exception the passed in exception if it can't handle it |
144 | 144 | * @return Response a Response object or null in case that the exception could not be handled |
145 | 145 | */ |
146 | - public function afterException($controller, $methodName, \Exception $exception){ |
|
147 | - if($exception instanceof SecurityException){ |
|
148 | - $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
149 | - if($exception->getCode() !== 0) { |
|
146 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
147 | + if ($exception instanceof SecurityException) { |
|
148 | + $response = new JSONResponse(['message' => $exception->getMessage()]); |
|
149 | + if ($exception->getCode() !== 0) { |
|
150 | 150 | $response->setStatus($exception->getCode()); |
151 | 151 | } else { |
152 | 152 | $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
@@ -143,7 +143,7 @@ |
||
143 | 143 | $format = $this->request->getParam('format'); |
144 | 144 | |
145 | 145 | // if none is given try the first Accept header |
146 | - if($format === null) { |
|
146 | + if ($format === null) { |
|
147 | 147 | $headers = $this->request->getHeader('Accept'); |
148 | 148 | $format = $controller->getResponderByHTTPHeader($headers, 'xml'); |
149 | 149 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | * @param Response $response |
72 | 72 | * @return Response |
73 | 73 | */ |
74 | - public function afterController($controller, $methodName, Response $response){ |
|
74 | + public function afterController($controller, $methodName, Response $response) { |
|
75 | 75 | $useSession = $this->reflector->hasAnnotation('UseSession'); |
76 | 76 | if ($useSession) { |
77 | 77 | $this->session->close(); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Constructor |
54 | 54 | */ |
55 | - public function __construct(){ |
|
55 | + public function __construct() { |
|
56 | 56 | $this->middlewares = array(); |
57 | 57 | $this->middlewareCounter = 0; |
58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * Adds a new middleware |
63 | 63 | * @param Middleware $middleWare the middleware which will be added |
64 | 64 | */ |
65 | - public function registerMiddleware(Middleware $middleWare){ |
|
65 | + public function registerMiddleware(Middleware $middleWare) { |
|
66 | 66 | array_push($this->middlewares, $middleWare); |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * returns an array with all middleware elements |
72 | 72 | * @return array the middlewares |
73 | 73 | */ |
74 | - public function getMiddlewares(){ |
|
74 | + public function getMiddlewares() { |
|
75 | 75 | return $this->middlewares; |
76 | 76 | } |
77 | 77 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | * @param string $methodName the name of the method that will be called on |
85 | 85 | * the controller |
86 | 86 | */ |
87 | - public function beforeController(Controller $controller, $methodName){ |
|
87 | + public function beforeController(Controller $controller, $methodName) { |
|
88 | 88 | // we need to count so that we know which middlewares we have to ask in |
89 | 89 | // case there is an exception |
90 | 90 | $middlewareCount = count($this->middlewares); |
91 | - for($i = 0; $i < $middlewareCount; $i++){ |
|
91 | + for ($i = 0; $i < $middlewareCount; $i++) { |
|
92 | 92 | $this->middlewareCounter++; |
93 | 93 | $middleware = $this->middlewares[$i]; |
94 | 94 | $middleware->beforeController($controller, $methodName); |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | * exception |
112 | 112 | * @throws \Exception the passed in exception if it can't handle it |
113 | 113 | */ |
114 | - public function afterException(Controller $controller, $methodName, \Exception $exception){ |
|
115 | - for($i=$this->middlewareCounter-1; $i>=0; $i--){ |
|
114 | + public function afterException(Controller $controller, $methodName, \Exception $exception) { |
|
115 | + for ($i = $this->middlewareCounter - 1; $i >= 0; $i--) { |
|
116 | 116 | $middleware = $this->middlewares[$i]; |
117 | 117 | try { |
118 | 118 | return $middleware->afterException($controller, $methodName, $exception); |
119 | - } catch(\Exception $exception){ |
|
119 | + } catch (\Exception $exception) { |
|
120 | 120 | continue; |
121 | 121 | } |
122 | 122 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @param Response $response the generated response from the controller |
135 | 135 | * @return Response a Response object |
136 | 136 | */ |
137 | - public function afterController(Controller $controller, $methodName, Response $response){ |
|
138 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
137 | + public function afterController(Controller $controller, $methodName, Response $response) { |
|
138 | + for ($i = count($this->middlewares) - 1; $i >= 0; $i--) { |
|
139 | 139 | $middleware = $this->middlewares[$i]; |
140 | 140 | $response = $middleware->afterController($controller, $methodName, $response); |
141 | 141 | } |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param string $output the generated output from a response |
154 | 154 | * @return string the output that should be printed |
155 | 155 | */ |
156 | - public function beforeOutput(Controller $controller, $methodName, $output){ |
|
157 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
156 | + public function beforeOutput(Controller $controller, $methodName, $output) { |
|
157 | + for ($i = count($this->middlewares) - 1; $i >= 0; $i--) { |
|
158 | 158 | $middleware = $this->middlewares[$i]; |
159 | 159 | $output = $middleware->beforeOutput($controller, $methodName, $output); |
160 | 160 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | use OCP\AppFramework\Http\EmptyContentSecurityPolicy; |
27 | 27 | use OCP\AppFramework\Http\Response; |
28 | 28 | |
29 | -abstract class BaseResponse extends Response { |
|
29 | +abstract class BaseResponse extends Response { |
|
30 | 30 | /** @var array */ |
31 | 31 | protected $data; |
32 | 32 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | public function getStatus() { |
37 | 37 | |
38 | - $status = parent::getStatus(); |
|
38 | + $status = parent::getStatus(); |
|
39 | 39 | if ($status === API::RESPOND_UNAUTHORISED) { |
40 | 40 | return Http::STATUS_UNAUTHORIZED; |
41 | 41 | } else if ($status === API::RESPOND_NOT_FOUND) { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return int |
35 | 35 | */ |
36 | 36 | public function getStatus() { |
37 | - $status = parent::getStatus(); |
|
37 | + $status = parent::getStatus(); |
|
38 | 38 | if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
39 | 39 | return Http::STATUS_UNAUTHORIZED; |
40 | 40 | } |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
71 | 71 | ]; |
72 | 72 | |
73 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
74 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
73 | + $meta['totalitems'] = $this->itemsCount !== null ? (string) $this->itemsCount : ''; |
|
74 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string) $this->itemsPerPage : ''; |
|
75 | 75 | |
76 | 76 | return $this->renderResult($meta); |
77 | 77 | } |