Skip to content

Commit 788e535

Browse files
committed
Update to PHP 8.2
1 parent 50152f5 commit 788e535

File tree

108 files changed

+702
-1331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+702
-1331
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.phar
44
/vendor/
55
docs/reactivex.github.io
66
build/
7+
.idea

.phpunit.result.cache

+1
Large diffs are not rendered by default.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=7.0.0",
23+
"php": ">=8.2",
2424
"react/promise": "^3 || ~2.2"
2525
},
2626
"require-dev": {

demo/create/createObservable.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

33
use Rx\Disposable\CallbackDisposable;
4+
use Rx\Observable\AnonymousObservable;
5+
use Rx\ObserverInterface;
46

57
require_once __DIR__ . '/../bootstrap.php';
68

79
//With Class
8-
$source = new \Rx\Observable\AnonymousObservable(function (\Rx\ObserverInterface $observer) {
10+
$source = new AnonymousObservable(function (ObserverInterface $observer) {
911
$observer->onNext(42);
1012
$observer->onCompleted();
1113

demo/custom-operator/Rot13Operator.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ class Rot13Operator implements OperatorInterface
1515
public function __invoke(ObservableInterface $observable, ObserverInterface $observer): DisposableInterface
1616
{
1717
return $observable->subscribe(
18-
function ($json) use ($observer) {
19-
$observer->onNext(str_rot13($json));
20-
},
21-
[$observer, 'onError'],
22-
[$observer, 'onCompleted']
18+
fn ($json) => $observer->onNext(str_rot13($json)),
19+
fn ($e) => $observer->onError($e),
20+
fn () => $observer->onCompleted()
2321
);
2422
}
2523
}

demo/zip/zip.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
function ($array) use ($observer) {
2121
$observer->onNext(json_encode($array));
2222
},
23-
[$observer, 'onError'],
24-
[$observer, 'onCompleted']
23+
fn ($e) => $observer->onError($e),
24+
fn () => $observer->onCompleted()
2525
));

src/Disposable/BinaryDisposable.php

+6-23
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,16 @@
66

77
use Rx\DisposableInterface;
88

9-
/**
10-
* Class BinaryDisposable
11-
* @package Rx\Disposable
12-
*/
139
class BinaryDisposable implements DisposableInterface
1410
{
15-
/** @var \Rx\DisposableInterface */
16-
private $first;
17-
18-
/** @var \Rx\DisposableInterface */
19-
private $second;
20-
21-
/** @var bool */
22-
protected $isDisposed = false;
23-
24-
/**
25-
* BinaryDisposable constructor.
26-
* @param $first
27-
* @param $second
28-
*/
29-
public function __construct(DisposableInterface $first, DisposableInterface $second)
30-
{
31-
$this->first = $first;
32-
$this->second = $second;
11+
public function __construct(
12+
private null|DisposableInterface $first,
13+
private null|DisposableInterface $second,
14+
protected bool $isDisposed = false
15+
) {
3316
}
3417

35-
public function dispose()
18+
public function dispose(): void
3619
{
3720
if ($this->isDisposed) {
3821
return;

src/Disposable/CallbackDisposable.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88

99
class CallbackDisposable implements DisposableInterface
1010
{
11-
private $action;
12-
private $disposed = false;
13-
14-
public function __construct(callable $action)
15-
{
16-
$this->action = $action;
11+
public function __construct(
12+
private \Closure $action,
13+
private bool $disposed = false
14+
) {
1715
}
1816

19-
public function dispose()
17+
public function dispose(): void
2018
{
2119
if ($this->disposed) {
2220
return;

src/Disposable/CompositeDisposable.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
class CompositeDisposable implements DisposableInterface
1010
{
11-
private $disposables;
12-
private $isDisposed = false;
1311

14-
public function __construct(array $disposables = [])
15-
{
16-
$this->disposables = $disposables;
12+
public function __construct(
13+
private array $disposables = [],
14+
private bool $isDisposed = false
15+
) {
1716
}
1817

19-
public function dispose()
18+
public function dispose(): void
2019
{
2120
if ($this->isDisposed) {
2221
return;
@@ -32,7 +31,7 @@ public function dispose()
3231
}
3332
}
3433

35-
public function add(DisposableInterface $disposable)
34+
public function add(DisposableInterface $disposable): void
3635
{
3736
if ($this->isDisposed) {
3837
$disposable->dispose();
@@ -65,12 +64,12 @@ public function contains(DisposableInterface $disposable): bool
6564
return in_array($disposable, $this->disposables, true);
6665
}
6766

68-
public function count()
67+
public function count(): int
6968
{
7069
return count($this->disposables);
7170
}
7271

73-
public function clear()
72+
public function clear(): void
7473
{
7574
$disposables = $this->disposables;
7675
$this->disposables = [];

src/Disposable/EmptyDisposable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class EmptyDisposable implements DisposableInterface
1010
{
11-
public function dispose()
11+
public function dispose(): void
1212
{
1313
// do nothing \o/
1414
}

src/Disposable/RefCountDisposable.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88

99
class RefCountDisposable implements DisposableInterface
1010
{
11-
private $count = 0;
12-
private $disposable;
13-
private $isDisposed = false;
14-
private $isPrimaryDisposed = false;
1511

16-
public function __construct(DisposableInterface $disposable)
17-
{
18-
$this->disposable = $disposable;
12+
public function __construct(
13+
private readonly DisposableInterface $disposable,
14+
private int $count = 0,
15+
private bool $isDisposed = false,
16+
private bool $isPrimaryDisposed = false
17+
) {
1918
}
2019

21-
public function dispose()
20+
public function dispose(): void
2221
{
2322
if ($this->isDisposed) {
2423
return;
@@ -32,13 +31,13 @@ public function dispose()
3231
}
3332
}
3433

35-
public function getDisposable()
34+
public function getDisposable(): DisposableInterface|CallbackDisposable
3635
{
3736
if (!$this->isDisposed) {
3837
return $this->createInnerDisposable();
3938
}
4039

41-
return new CallbackDisposable(function () {
40+
return new CallbackDisposable(function (): void {
4241
}); // no op
4342
}
4443

@@ -57,7 +56,7 @@ private function createInnerDisposable(): DisposableInterface
5756
$this->count++;
5857
$isInnerDisposed = false;
5958

60-
return new CallbackDisposable(function () use (&$isInnerDisposed) {
59+
return new CallbackDisposable(function () use (&$isInnerDisposed): void {
6160
if ($this->isDisposed()) {
6261
return;
6362
}

src/Disposable/ScheduledDisposable.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,22 @@
99

1010
class ScheduledDisposable implements DisposableInterface
1111
{
12-
/** @var DisposableInterface */
13-
private $disposable;
14-
15-
/** @var SchedulerInterface */
16-
private $scheduler;
17-
18-
/** @var bool */
19-
protected $isDisposed = false;
20-
21-
public function __construct(SchedulerInterface $scheduler, DisposableInterface $disposable)
22-
{
23-
$this->scheduler = $scheduler;
24-
$this->disposable = $disposable;
12+
public function __construct(
13+
private SchedulerInterface $scheduler,
14+
private DisposableInterface $disposable,
15+
protected bool $isDisposed = false
16+
) {
2517
}
2618

27-
public function dispose()
19+
public function dispose(): void
2820
{
2921
if ($this->isDisposed) {
3022
return;
3123
}
3224

3325
$this->isDisposed = true;
3426

35-
$this->scheduler->schedule(function () {
27+
$this->scheduler->schedule(function (): void {
3628
$this->disposable->dispose();
3729
});
3830
}

src/Disposable/SerialDisposable.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66

77
use Rx\DisposableInterface;
88

9-
/**
10-
* Class SerialDisposable
11-
* @package Rx\Disposable
12-
*/
139
class SerialDisposable implements DisposableInterface
1410
{
15-
/** @var bool */
16-
private $isDisposed = false;
11+
private bool $isDisposed = false;
1712

18-
/** @var DisposableInterface */
19-
private $disposable = null;
13+
private ?DisposableInterface $disposable = null;
2014

21-
public function dispose()
15+
public function dispose(): void
2216
{
2317
if ($this->isDisposed) {
2418
return;
@@ -33,18 +27,12 @@ public function dispose()
3327
}
3428
}
3529

36-
/**
37-
* @return DisposableInterface
38-
*/
39-
public function getDisposable()
30+
public function getDisposable(): null|DisposableInterface
4031
{
4132
return $this->disposable;
4233
}
4334

44-
/**
45-
* @param DisposableInterface $disposable
46-
*/
47-
public function setDisposable(DisposableInterface $disposable)
35+
public function setDisposable(DisposableInterface $disposable): void
4836
{
4937
$shouldDispose = $this->isDisposed;
5038

src/Disposable/SingleAssignmentDisposable.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
class SingleAssignmentDisposable implements DisposableInterface
1111
{
12-
private $current;
13-
private $isDisposed = false;
12+
private null|DisposableInterface $current = null;
13+
private bool $isDisposed = false;
1414

15-
public function dispose()
15+
public function dispose(): void
1616
{
1717
$old = null;
1818

@@ -27,7 +27,7 @@ public function dispose()
2727
}
2828
}
2929

30-
public function setDisposable(DisposableInterface $disposable = null)
30+
public function setDisposable(DisposableInterface $disposable = null): void
3131
{
3232
if ($this->current) {
3333
throw new RuntimeException('Disposable has already been assigned.');
@@ -42,12 +42,12 @@ public function setDisposable(DisposableInterface $disposable = null)
4242
}
4343
}
4444

45-
public function getDisposable()
45+
public function getDisposable(): null|DisposableInterface
4646
{
4747
return $this->current;
4848
}
4949

50-
public function isDisposed()
50+
public function isDisposed(): bool
5151
{
5252
return $this->isDisposed;
5353
}

src/Notification.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,28 @@
99
*/
1010
abstract class Notification
1111
{
12-
private $kind;
1312

1413
/**
1514
* @param mixed $kind Kind of notification
1615
*/
17-
public function __construct($kind)
16+
public function __construct(private $kind)
1817
{
19-
$this->kind = $kind;
2018
}
2119

2220
public function accept($observerOrOnNext, $onError = null, $onCompleted = null)
2321
{
2422
if (null === $onError && null === $onCompleted && $observerOrOnNext instanceof ObserverInterface) {
2523
$this->doAcceptObservable($observerOrOnNext);
2624

27-
return;
25+
return null;
2826
}
2927

3028
return $this->doAccept($observerOrOnNext, $onError, $onCompleted);
3129
}
3230

3331
public function equals($other): bool
3432
{
35-
return (string)$this === (string)$other;
33+
return (string) $this === (string)$other;
3634
}
3735

3836
abstract protected function doAcceptObservable(ObserverInterface $observer);

src/Notification/OnErrorNotification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class OnErrorNotification extends Notification
1111
{
12-
private $exception;
12+
private \Throwable $exception;
1313

1414
public function __construct(\Throwable $exception)
1515
{

0 commit comments

Comments
 (0)