Skip to content

Commit

Permalink
Refactor lib/private/ocs
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <[email protected]>

Refactor lib/private/ocs

Signed-off-by: Hamid Dehnavi <[email protected]>

Refactor lib/private/ocs

Co-authored-by: Faraz Samapoor <[email protected]>
Signed-off-by: Hamid Dehnavi <[email protected]>

Add adjustments based on the review

Signed-off-by: Hamid Dehnavi <[email protected]>

replace qualifier with an import

Signed-off-by: Hamid Dehnavi <[email protected]>

refactor lib/private/OCS

Signed-off-by: Hamid Dehnavi <[email protected]>
  • Loading branch information
shdehnavi authored and skjnldsv committed Feb 23, 2024
1 parent a88c1bd commit 09b3702
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
10 changes: 4 additions & 6 deletions lib/private/OCS/CoreCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@
* @package OC\OCS
*/
class CoreCapabilities implements ICapability {
/** @var IConfig */
private $config;

/**
* @param IConfig $config
*/
public function __construct(IConfig $config) {
$this->config = $config;
public function __construct(
private IConfig $config,
) {
}

/**
* Return this classes capabilities
*/
public function getCapabilities() {
public function getCapabilities(): array {
return [
'core' => [
'pollinterval' => $this->config->getSystemValue('pollinterval', 60),
Expand Down
4 changes: 2 additions & 2 deletions lib/private/OCS/DiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

class DiscoveryService implements IDiscoveryService {
/** @var ICache */
private $cache;
private ICache $cache;

/** @var IClient */
private $client;
private IClient $client;

/**
* @param ICacheFactory $cacheFactory
Expand Down
10 changes: 4 additions & 6 deletions lib/private/OCS/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
namespace OC\OCS;

class Exception extends \Exception {
/** @var Result */
private $result;

public function __construct(Result $result) {
public function __construct(
private Result $result,
) {
parent::__construct();
$this->result = $result;
}

public function getResult() {
public function getResult(): Result {
return $this->result;
}
}
21 changes: 11 additions & 10 deletions lib/private/OCS/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@
*/
namespace OC\OCS;

class Provider extends \OCP\AppFramework\Controller {
/** @var \OCP\App\IAppManager */
private $appManager;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;

class Provider extends Controller {
/**
* @param string $appName
* @param \OCP\IRequest $request
* @param \OCP\App\IAppManager $appManager
* @param IRequest $request
* @param IAppManager $appManager
*/
public function __construct($appName,
\OCP\IRequest $request,
\OCP\App\IAppManager $appManager) {
private \OCP\App\IAppManager $appManager) {
parent::__construct($appName, $request);
$this->appManager = $appManager;
}

/**
* @return \OCP\AppFramework\Http\JSONResponse
* @return JSONResponse
*/
public function buildProviderList() {
public function buildProviderList(): JSONResponse {
$services = [
'PRIVATE_DATA' => [
'version' => 1,
Expand Down Expand Up @@ -108,7 +109,7 @@ public function buildProviderList() {
];
}

return new \OCP\AppFramework\Http\JSONResponse([
return new JSONResponse([
'version' => 2,
'services' => $services,
]);
Expand Down
37 changes: 20 additions & 17 deletions lib/private/OCS/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
namespace OC\OCS;

class Result {
/** @var array */
protected $data;
protected array $data;

/** @var null|string */
protected $message;
protected ?string $message;

/** @var int */
protected $statusCode;
protected int $statusCode;

/** @var integer */
protected $items;
Expand All @@ -47,16 +46,17 @@ class Result {
protected $perPage;

/** @var array */
private $headers = [];
private array $headers = [];

/**
* create the OCS_Result object
* @param mixed $data the data to return
*
* @param mixed|null $data the data to return
* @param int $code
* @param null|string $message
* @param string|null $message
* @param array $headers
*/
public function __construct($data = null, $code = 100, $message = null, $headers = []) {
public function __construct(mixed $data = null, int $code = 100, string $message = null, array $headers = []) {
if ($data === null) {
$this->data = [];
} elseif (!is_array($data)) {
Expand All @@ -71,33 +71,35 @@ public function __construct($data = null, $code = 100, $message = null, $headers

/**
* optionally set the total number of items available
*
* @param int $items
*/
public function setTotalItems($items) {
public function setTotalItems(int $items): void {
$this->items = $items;
}

/**
* optionally set the the number of items per page
* optionally set the number of items per page
*
* @param int $items
*/
public function setItemsPerPage($items) {
public function setItemsPerPage(int $items): void {
$this->perPage = $items;
}

/**
* get the status code
* @return int
*/
public function getStatusCode() {
public function getStatusCode(): int {
return $this->statusCode;
}

/**
* get the meta data for the result
* @return array
*/
public function getMeta() {
public function getMeta(): array {
$meta = [];
$meta['status'] = $this->succeeded() ? 'ok' : 'failure';
$meta['statuscode'] = $this->statusCode;
Expand All @@ -115,25 +117,26 @@ public function getMeta() {
* get the result data
* @return array
*/
public function getData() {
public function getData(): array {
return $this->data;
}

/**
* return bool Whether the method succeeded
* @return bool
*/
public function succeeded() {
public function succeeded(): bool {
return ($this->statusCode == 100);
}

/**
* Adds a new header to the response
*
* @param string $name The name of the HTTP header
* @param string $value The value, null will delete it
* @return $this
*/
public function addHeader($name, $value) {
public function addHeader(string $name, ?string $value): static {
$name = trim($name); // always remove leading and trailing whitespace
// to be able to reliably check for security
// headers
Expand All @@ -151,7 +154,7 @@ public function addHeader($name, $value) {
* Returns the set headers
* @return array the headers
*/
public function getHeaders() {
public function getHeaders(): array {
return $this->headers;
}
}

0 comments on commit 09b3702

Please sign in to comment.