Skip to content

Commit

Permalink
Fix response types
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Jun 14, 2023
1 parent 8b1d849 commit c5d818d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/settings/lib/WellKnown/ChangePasswordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Settings\WellKnown;

use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\Http\WellKnown\GenericResponse;
use OCP\Http\WellKnown\IHandler;
use OCP\Http\WellKnown\IRequestContext;
Expand All @@ -45,6 +46,7 @@ public function handle(string $service, IRequestContext $context, ?IResponse $pr
return $previousResponse;
}

/** @var Response $response */
$response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'security']));
return new GenericResponse($response);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/AppFramework/Middleware/CompressionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* @author Morris Jobke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -46,6 +47,9 @@ public function __construct(IRequest $request) {
$this->useGZip = false;
}

/**
* @param Response<int, array<string, mixed>> $response
*/
public function afterController($controller, $methodName, Response $response) {
// By default we do not gzip
$allowGzip = false;
Expand Down
7 changes: 4 additions & 3 deletions lib/private/AppFramework/Middleware/OCSMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Joas Schilling <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -90,7 +91,7 @@ public function afterException($controller, $methodName, \Exception $exception)
/**
* @param Controller $controller
* @param string $methodName
* @param Response $response
* @param Response|JSONResponse $response
* @return \OCP\AppFramework\Http\Response
*/
public function afterController($controller, $methodName, Response $response) {
Expand All @@ -102,7 +103,7 @@ public function afterController($controller, $methodName, Response $response) {
if ($response->getStatus() === Http::STATUS_UNAUTHORIZED) {
$message = '';
if ($response instanceof JSONResponse) {
/** @var DataResponse $response */
/** @var DataResponse<Http::STATUS_UNAUTHORIZED, array, array{}> $response */
$message = $response->getData()['message'];
}

Expand All @@ -111,7 +112,7 @@ public function afterController($controller, $methodName, Response $response) {
if ($response->getStatus() === Http::STATUS_FORBIDDEN) {
$message = '';
if ($response instanceof JSONResponse) {
/** @var DataResponse $response */
/** @var DataResponse<Http::STATUS_FORBIDDEN, array, array{}> $response */
$message = $response->getData()['message'];
}

Expand Down
10 changes: 9 additions & 1 deletion lib/private/AppFramework/OCS/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Joas Schilling <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -30,6 +31,13 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends Response<S, H>
*/
abstract class BaseResponse extends Response {
/** @var array */
protected $data;
Expand All @@ -49,7 +57,7 @@ abstract class BaseResponse extends Response {
/**
* BaseResponse constructor.
*
* @param DataResponse $dataResponse
* @param DataResponse<S, T, H> $dataResponse
* @param string $format
* @param string|null $statusMessage
* @param int|null $itemsCount
Expand Down
10 changes: 10 additions & 0 deletions lib/private/AppFramework/OCS/V1Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Christoph Wurst <[email protected]>
* @author Joas Schilling <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -25,13 +26,22 @@
namespace OC\AppFramework\OCS;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends BaseResponse<S, DataResponseType, H>
*/
class V1Response extends BaseResponse {
/**
* The V1 endpoint has very limited http status codes basically everything
* is status 200 except 401
*
* @psalm-suppress ImplementedReturnTypeMismatch Expected because we match some status codes
* @return int
*/
public function getStatus() {
Expand Down
10 changes: 10 additions & 0 deletions lib/private/AppFramework/OCS/V2Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @author Christoph Wurst <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -24,13 +25,22 @@
namespace OC\AppFramework\OCS;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

/**
* @psalm-import-type DataResponseType from DataResponse
* @template S of int
* @template-covariant T of DataResponseType
* @template H of array<string, mixed>
* @template-extends BaseResponse<S, DataResponseType, H>
*/
class V2Response extends BaseResponse {
/**
* The V2 endpoint just passes on status codes.
* Of course we have to map the OCS specific codes to proper HTTP status codes
*
* @psalm-suppress ImplementedReturnTypeMismatch Expected because we match some status codes
* @return int
*/
public function getStatus() {
Expand Down

0 comments on commit c5d818d

Please sign in to comment.