<commit_before><?php
/**
 * This file is part of the Passwords App
 * created by <NAME>
 * and licensed under the AGPL.
 */

namespace OCA\Passwords\Controller\Api;

use OCA\Passwords\Exception\ApiException;
use OCA\Passwords\Services\UserSettingsService;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;

/**
 * Class SettingsApiController
 *
 * @package OCA\Passwords\Controller\Api
 */
class SettingsApiController extends AbstractApiController {

    /**
     * @var UserSettingsService
     */
    protected $settings;

    /**
     * SettingsApiController constructor.
     *
     * @param IRequest            $request
     * @param UserSettingsService $settings
     */
    public function __construct(IRequest $request, UserSettingsService $settings) {
        parent::__construct($request);
        $this->settings = $settings;
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function get(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key) {
            $settings[ $key ] = $this->settings->get($key);
        }

        return $this->createJsonResponse($settings);
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws ApiException
     */
    public function set(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key => $value) {
            $settings[ $key ] = $this->settings->set($key, $value);
        }

        return $this->createJsonResponse($settings);
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @param array|null $scopes
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function list(array $scopes = null): JSONResponse {
        return $this->createJsonResponse(
            $this->settings->list($scopes)
        );
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function reset(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key) {
            if($key !== null) $settings[ $key ] = $this->settings->reset($key);
        }

        return $this->createJsonResponse($settings);
    }
}<commit_msg>Fix settings api in NC 20<commit_after><?php
/**
 * This file is part of the Passwords App
 * created by <NAME>
 * and licensed under the AGPL.
 */

namespace OCA\Passwords\Controller\Api;

use OCA\Passwords\Exception\ApiException;
use OCA\Passwords\Services\UserSettingsService;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;

/**
 * Class SettingsApiController
 *
 * @package OCA\Passwords\Controller\Api
 */
class SettingsApiController extends AbstractApiController {

    /**
     * @var UserSettingsService
     */
    protected $settings;

    /**
     * SettingsApiController constructor.
     *
     * @param IRequest            $request
     * @param UserSettingsService $settings
     */
    public function __construct(IRequest $request, UserSettingsService $settings) {
        parent::__construct($request);
        $this->settings = $settings;
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function get(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key) {
            $settings[ $key ] = $this->settings->get($key);
        }

        return $this->createJsonResponse($settings);
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws ApiException
     */
    public function set(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key => $value) {
            $settings[ $key ] = $this->settings->set($key, $value);
        }

        return $this->createJsonResponse($settings);
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @param array|null $scopes
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function list(array $scopes = null): JSONResponse {
        return $this->createJsonResponse(
            $this->settings->list($scopes)
        );
    }

    /**
     * @CORS
     * @NoCSRFRequired
     * @NoAdminRequired
     *
     * @return JSONResponse
     * @throws \Exception
     */
    public function reset(): JSONResponse {
        $params = $this->getParameterArray();
        if(empty($params)) return $this->createJsonResponse([]);

        $settings = [];
        foreach($params as $key) {
            $settings[ $key ] = $this->settings->reset($key);
        }

        return $this->createJsonResponse($settings);
    }

    /**
     * @return array
     */
    protected function getParameterArray(): array {
        $params = parent::getParameterArray();
        if(array_key_exists('action', $params)) unset($params['action']);

        return $params;
    }
}
{'fraction_non_alphanumeric': 0.13647686832740213, 'fraction_numerical': 0.00035587188612099647, 'mean_word_length': 2.3181818181818183, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5706520', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1574, 'n_words': 324}