aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-09-02 17:28:06 +0200
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-09-09 10:46:29 +0200
commit37569466de10a3e44e4d0e4b2aad96cf2c544ea5 (patch)
treed8e788aef3b5d56d2012f63676b756b5b7c6a7b9 /lib/private
parentea32d17d88b52a07e04bbc2f8ea0e8d81e84b884 (diff)
downloadnextcloud-server-37569466de10a3e44e4d0e4b2aad96cf2c544ea5.tar.gz
nextcloud-server-37569466de10a3e44e4d0e4b2aad96cf2c544ea5.zip
fix: A bit of code cleanup in OC\AppFramework\OCS\ApiHelper
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/AppFramework/OCS/ApiHelper.php47
1 files changed, 17 insertions, 30 deletions
diff --git a/lib/private/AppFramework/OCS/ApiHelper.php b/lib/private/AppFramework/OCS/ApiHelper.php
index fb4b7e7563b..78a637623d0 100644
--- a/lib/private/AppFramework/OCS/ApiHelper.php
+++ b/lib/private/AppFramework/OCS/ApiHelper.php
@@ -8,26 +8,25 @@
namespace OC\AppFramework\OCS;
-use OCP\API;
+use OC\OCS\Result;
use OCP\AppFramework\Http;
+use OCP\AppFramework\OCSController;
+use OCP\IRequest;
+use OCP\Server;
+use XMLWriter;
class ApiHelper {
/**
- * api actions
- */
- protected static $actions = [];
-
- /**
* respond to a call
* @param \OC\OCS\Result $result
* @param string $format the format xml|json
* @psalm-taint-escape html
*/
- public static function respond($result, $format = 'xml') {
- $request = \OC::$server->getRequest();
+ public static function respond(Result $result, string $format = 'xml'): void {
+ $request = Server::get(IRequest::class);
// Send 401 headers if unauthorised
- if ($result->getStatusCode() === \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED) {
+ if ($result->getStatusCode() === OCSController::RESPOND_UNAUTHORISED) {
// If request comes from JS return dummy auth request
if ($request->getHeader('X-Requested-With') === 'XMLHttpRequest') {
header('WWW-Authenticate: DummyBasic realm="Authorisation Required"');
@@ -56,10 +55,7 @@ class ApiHelper {
echo $body;
}
- /**
- * @param XMLWriter $writer
- */
- private static function toXML($array, $writer) {
+ private static function toXML(iterable $array, XMLWriter $writer): void {
foreach ($array as $k => $v) {
if ($k[0] === '@') {
$writer->writeAttribute(substr($k, 1), $v);
@@ -86,9 +82,8 @@ class ApiHelper {
/**
* Based on the requested format the response content type is set
- * @param string $format
*/
- public static function setContentType($format = null) {
+ public static function setContentType(?string $format = null): void {
$format = is_null($format) ? self::requestedFormat() : $format;
if ($format === 'xml') {
header('Content-type: text/xml; charset=UTF-8');
@@ -103,29 +98,21 @@ class ApiHelper {
header('Content-Type: application/octet-stream; charset=utf-8');
}
- /**
- * @param \OCP\IRequest $request
- * @return bool
- */
- protected static function isV2(\OCP\IRequest $request) {
+ protected static function isV2(IRequest $request): bool {
$script = $request->getScriptName();
return str_ends_with($script, '/ocs/v2.php');
}
- /**
- * @param integer $sc
- * @return int
- */
- public static function mapStatusCodes($sc) {
+ public static function mapStatusCodes(int $sc): ?int {
switch ($sc) {
- case \OCP\AppFramework\OCSController::RESPOND_NOT_FOUND:
+ case OCSController::RESPOND_NOT_FOUND:
return Http::STATUS_NOT_FOUND;
- case \OCP\AppFramework\OCSController::RESPOND_SERVER_ERROR:
+ case OCSController::RESPOND_SERVER_ERROR:
return Http::STATUS_INTERNAL_SERVER_ERROR;
- case \OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR:
+ case OCSController::RESPOND_UNKNOWN_ERROR:
return Http::STATUS_INTERNAL_SERVER_ERROR;
- case \OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED:
+ case OCSController::RESPOND_UNAUTHORISED:
// already handled for v1
return null;
case 100:
@@ -143,7 +130,7 @@ class ApiHelper {
* @param string $format
* @return string
*/
- public static function renderResult($format, $meta, $data) {
+ public static function renderResult(string $format, $meta, $data): string {
$response = [
'ocs' => [
'meta' => $meta,