Skip to content

Commit 5e043f9

Browse files
committed
Refactor lib/private/ocs
Co-authored-by: Faraz Samapoor <f.samapoor@gmail.com> Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com> Add adjustments based on the review Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com> replace qualifier with an import Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com> refactor lib/private/OCS Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
1 parent 9e10b1d commit 5e043f9

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

lib/private/OCS/CoreCapabilities.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@
3232
* @package OC\OCS
3333
*/
3434
class CoreCapabilities implements ICapability {
35-
/** @var IConfig */
36-
private $config;
37-
3835
/**
3936
* @param IConfig $config
4037
*/
41-
public function __construct(IConfig $config) {
42-
$this->config = $config;
38+
public function __construct(
39+
private IConfig $config,
40+
) {
4341
}
4442

4543
/**
4644
* Return this classes capabilities
4745
*/
48-
public function getCapabilities() {
46+
public function getCapabilities(): array {
4947
return [
5048
'core' => [
5149
'pollinterval' => $this->config->getSystemValue('pollinterval', 60),

lib/private/OCS/DiscoveryService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737

3838
class DiscoveryService implements IDiscoveryService {
3939
/** @var ICache */
40-
private $cache;
40+
private ICache $cache;
4141

4242
/** @var IClient */
43-
private $client;
43+
private IClient $client;
4444

4545
/**
4646
* @param ICacheFactory $cacheFactory

lib/private/OCS/Exception.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
namespace OC\OCS;
2424

2525
class Exception extends \Exception {
26-
/** @var Result */
27-
private $result;
28-
29-
public function __construct(Result $result) {
26+
public function __construct(
27+
private Result $result,
28+
) {
3029
parent::__construct();
31-
$this->result = $result;
3230
}
3331

34-
public function getResult() {
32+
public function getResult(): Result {
3533
return $this->result;
3634
}
3735
}

lib/private/OCS/Provider.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@
2424
*/
2525
namespace OC\OCS;
2626

27-
class Provider extends \OCP\AppFramework\Controller {
28-
/** @var \OCP\App\IAppManager */
29-
private $appManager;
27+
use OCP\App\IAppManager;
28+
use OCP\AppFramework\Controller;
29+
use OCP\AppFramework\Http\JSONResponse;
30+
use OCP\IRequest;
3031

32+
class Provider extends Controller {
3133
/**
3234
* @param string $appName
33-
* @param \OCP\IRequest $request
34-
* @param \OCP\App\IAppManager $appManager
35+
* @param IRequest $request
36+
* @param IAppManager $appManager
3537
*/
3638
public function __construct($appName,
3739
\OCP\IRequest $request,
3840
\OCP\App\IAppManager $appManager) {
3941
parent::__construct($appName, $request);
40-
$this->appManager = $appManager;
4142
}
4243

4344
/**
44-
* @return \OCP\AppFramework\Http\JSONResponse
45+
* @return JSONResponse
4546
*/
46-
public function buildProviderList() {
47+
public function buildProviderList(): JSONResponse {
4748
$services = [
4849
'PRIVATE_DATA' => [
4950
'version' => 1,
@@ -108,7 +109,7 @@ public function buildProviderList() {
108109
];
109110
}
110111

111-
return new \OCP\AppFramework\Http\JSONResponse([
112+
return new JSONResponse([
112113
'version' => 2,
113114
'services' => $services,
114115
]);

lib/private/OCS/Result.php

+22-19
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@
3131
namespace OC\OCS;
3232

3333
class Result {
34-
/** @var array */
35-
protected $data;
34+
protected array $data;
3635

3736
/** @var null|string */
38-
protected $message;
37+
protected ?string $message;
3938

4039
/** @var int */
41-
protected $statusCode;
40+
protected int $statusCode;
4241

4342
/** @var integer */
44-
protected $items;
43+
protected int $items;
4544

4645
/** @var integer */
47-
protected $perPage;
46+
protected int $perPage;
4847

4948
/** @var array */
50-
private $headers = [];
49+
private array $headers = [];
5150

5251
/**
5352
* create the OCS_Result object
54-
* @param mixed $data the data to return
53+
*
54+
* @param mixed|null $data the data to return
5555
* @param int $code
56-
* @param null|string $message
56+
* @param string|null $message
5757
* @param array $headers
5858
*/
59-
public function __construct($data = null, $code = 100, $message = null, $headers = []) {
59+
public function __construct(mixed $data = null, int $code = 100, string $message = null, array $headers = []) {
6060
if ($data === null) {
6161
$this->data = [];
6262
} elseif (!is_array($data)) {
@@ -71,33 +71,35 @@ public function __construct($data = null, $code = 100, $message = null, $headers
7171

7272
/**
7373
* optionally set the total number of items available
74+
*
7475
* @param int $items
7576
*/
76-
public function setTotalItems($items) {
77+
public function setTotalItems(int $items): void {
7778
$this->items = $items;
7879
}
7980

8081
/**
81-
* optionally set the the number of items per page
82+
* optionally set the number of items per page
83+
*
8284
* @param int $items
8385
*/
84-
public function setItemsPerPage($items) {
86+
public function setItemsPerPage(int $items): void {
8587
$this->perPage = $items;
8688
}
8789

8890
/**
8991
* get the status code
9092
* @return int
9193
*/
92-
public function getStatusCode() {
94+
public function getStatusCode(): int {
9395
return $this->statusCode;
9496
}
9597

9698
/**
9799
* get the meta data for the result
98100
* @return array
99101
*/
100-
public function getMeta() {
102+
public function getMeta(): array {
101103
$meta = [];
102104
$meta['status'] = $this->succeeded() ? 'ok' : 'failure';
103105
$meta['statuscode'] = $this->statusCode;
@@ -115,25 +117,26 @@ public function getMeta() {
115117
* get the result data
116118
* @return array
117119
*/
118-
public function getData() {
120+
public function getData(): array {
119121
return $this->data;
120122
}
121123

122124
/**
123125
* return bool Whether the method succeeded
124126
* @return bool
125127
*/
126-
public function succeeded() {
128+
public function succeeded(): bool {
127129
return ($this->statusCode == 100);
128130
}
129131

130132
/**
131133
* Adds a new header to the response
134+
*
132135
* @param string $name The name of the HTTP header
133136
* @param string $value The value, null will delete it
134137
* @return $this
135138
*/
136-
public function addHeader($name, $value) {
139+
public function addHeader(string $name, string $value): static {
137140
$name = trim($name); // always remove leading and trailing whitespace
138141
// to be able to reliably check for security
139142
// headers
@@ -151,7 +154,7 @@ public function addHeader($name, $value) {
151154
* Returns the set headers
152155
* @return array the headers
153156
*/
154-
public function getHeaders() {
157+
public function getHeaders(): array {
155158
return $this->headers;
156159
}
157160
}

0 commit comments

Comments
 (0)