Skip to content

Commit d7ed056

Browse files
committed
fix: Improve code quality in EventSource
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent a9f7131 commit d7ed056

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

lib/private/EventSource.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* @copyright Copyright (c) 2016, ownCloud, Inc.
57
*
@@ -34,28 +36,16 @@
3436
use OCP\IRequest;
3537

3638
class EventSource implements IEventSource {
37-
/**
38-
* @var bool
39-
*/
40-
private $fallback;
41-
42-
/**
43-
* @var int
44-
*/
45-
private $fallBackId = 0;
46-
47-
/**
48-
* @var bool
49-
*/
50-
private $started = false;
51-
52-
private IRequest $request;
39+
private bool $fallback = false;
40+
private int $fallBackId = 0;
41+
private bool $started = false;
5342

54-
public function __construct(IRequest $request) {
55-
$this->request = $request;
43+
public function __construct(
44+
private IRequest $request,
45+
) {
5646
}
5747

58-
protected function init() {
48+
protected function init(): void {
5949
if ($this->started) {
6050
return;
6151
}
@@ -108,7 +98,7 @@ protected function init() {
10898
*/
10999
public function send($type, $data = null) {
110100
if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) {
111-
throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
101+
throw new \BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
112102
}
113103
$this->init();
114104
if (is_null($data)) {

lib/private/EventSourceFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
47
*

lib/public/IEventSource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface IEventSource {
3737
*
3838
* @param string $type One of success, notice, error, failure and done. Used in core/js/update.js
3939
* @param mixed $data
40+
* @return void
4041
*
4142
* if only one parameter is given, a typeless message will be send with that parameter as data
4243
* @since 8.0.0
@@ -45,6 +46,7 @@ public function send($type, $data = null);
4546

4647
/**
4748
* close the connection of the event source
49+
* @return void
4850
* @since 8.0.0
4951
*/
5052
public function close();

0 commit comments

Comments
 (0)