Browse Source

fix: Improve code quality in EventSource

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/45375/head
Côme Chilliet 4 weeks ago
parent
commit
d7ed056160
No account linked to committer's email address
3 changed files with 15 additions and 20 deletions
  1. 10
    20
      lib/private/EventSource.php
  2. 3
    0
      lib/private/EventSourceFactory.php
  3. 2
    0
      lib/public/IEventSource.php

+ 10
- 20
lib/private/EventSource.php View File

@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -34,28 +36,16 @@ use OCP\IEventSource;
use OCP\IRequest;

class EventSource implements IEventSource {
/**
* @var bool
*/
private $fallback;

/**
* @var int
*/
private $fallBackId = 0;

/**
* @var bool
*/
private $started = false;

private IRequest $request;
private bool $fallback = false;
private int $fallBackId = 0;
private bool $started = false;

public function __construct(IRequest $request) {
$this->request = $request;
public function __construct(
private IRequest $request,
) {
}

protected function init() {
protected function init(): void {
if ($this->started) {
return;
}
@@ -108,7 +98,7 @@ class EventSource implements IEventSource {
*/
public function send($type, $data = null) {
if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) {
throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
throw new \BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
}
$this->init();
if (is_null($data)) {

+ 3
- 0
lib/private/EventSourceFactory.php View File

@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
*

+ 2
- 0
lib/public/IEventSource.php View File

@@ -37,6 +37,7 @@ interface IEventSource {
*
* @param string $type One of success, notice, error, failure and done. Used in core/js/update.js
* @param mixed $data
* @return void
*
* if only one parameter is given, a typeless message will be send with that parameter as data
* @since 8.0.0
@@ -45,6 +46,7 @@ interface IEventSource {

/**
* close the connection of the event source
* @return void
* @since 8.0.0
*/
public function close();

Loading…
Cancel
Save