Skip to content

Commit

Permalink
Update to PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
daifma committed Oct 6, 2024
1 parent 50152f5 commit 788e535
Show file tree
Hide file tree
Showing 108 changed files with 702 additions and 1,331 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
/vendor/
docs/reactivex.github.io
build/
.idea
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=7.0.0",
"php": ">=8.2",
"react/promise": "^3 || ~2.2"
},
"require-dev": {
Expand Down
4 changes: 3 additions & 1 deletion demo/create/createObservable.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

use Rx\Disposable\CallbackDisposable;
use Rx\Observable\AnonymousObservable;
use Rx\ObserverInterface;

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

//With Class
$source = new \Rx\Observable\AnonymousObservable(function (\Rx\ObserverInterface $observer) {
$source = new AnonymousObservable(function (ObserverInterface $observer) {
$observer->onNext(42);
$observer->onCompleted();

Expand Down
8 changes: 3 additions & 5 deletions demo/custom-operator/Rot13Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ class Rot13Operator implements OperatorInterface
public function __invoke(ObservableInterface $observable, ObserverInterface $observer): DisposableInterface
{
return $observable->subscribe(
function ($json) use ($observer) {
$observer->onNext(str_rot13($json));
},
[$observer, 'onError'],
[$observer, 'onCompleted']
fn ($json) => $observer->onNext(str_rot13($json)),
fn ($e) => $observer->onError($e),
fn () => $observer->onCompleted()
);
}
}
4 changes: 2 additions & 2 deletions demo/zip/zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
function ($array) use ($observer) {
$observer->onNext(json_encode($array));
},
[$observer, 'onError'],
[$observer, 'onCompleted']
fn ($e) => $observer->onError($e),
fn () => $observer->onCompleted()
));
29 changes: 6 additions & 23 deletions src/Disposable/BinaryDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,16 @@

use Rx\DisposableInterface;

/**
* Class BinaryDisposable
* @package Rx\Disposable
*/
class BinaryDisposable implements DisposableInterface
{
/** @var \Rx\DisposableInterface */
private $first;

/** @var \Rx\DisposableInterface */
private $second;

/** @var bool */
protected $isDisposed = false;

/**
* BinaryDisposable constructor.
* @param $first
* @param $second
*/
public function __construct(DisposableInterface $first, DisposableInterface $second)
{
$this->first = $first;
$this->second = $second;
public function __construct(
private null|DisposableInterface $first,
private null|DisposableInterface $second,
protected bool $isDisposed = false
) {
}

public function dispose()
public function dispose(): void
{
if ($this->isDisposed) {
return;
Expand Down
12 changes: 5 additions & 7 deletions src/Disposable/CallbackDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

class CallbackDisposable implements DisposableInterface
{
private $action;
private $disposed = false;

public function __construct(callable $action)
{
$this->action = $action;
public function __construct(
private \Closure $action,
private bool $disposed = false
) {
}

public function dispose()
public function dispose(): void
{
if ($this->disposed) {
return;
Expand Down
17 changes: 8 additions & 9 deletions src/Disposable/CompositeDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

class CompositeDisposable implements DisposableInterface
{
private $disposables;
private $isDisposed = false;

public function __construct(array $disposables = [])
{
$this->disposables = $disposables;
public function __construct(
private array $disposables = [],
private bool $isDisposed = false
) {
}

public function dispose()
public function dispose(): void
{
if ($this->isDisposed) {
return;
Expand All @@ -32,7 +31,7 @@ public function dispose()
}
}

public function add(DisposableInterface $disposable)
public function add(DisposableInterface $disposable): void
{
if ($this->isDisposed) {
$disposable->dispose();
Expand Down Expand Up @@ -65,12 +64,12 @@ public function contains(DisposableInterface $disposable): bool
return in_array($disposable, $this->disposables, true);
}

public function count()
public function count(): int
{
return count($this->disposables);
}

public function clear()
public function clear(): void
{
$disposables = $this->disposables;
$this->disposables = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Disposable/EmptyDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class EmptyDisposable implements DisposableInterface
{
public function dispose()
public function dispose(): void
{
// do nothing \o/
}
Expand Down
21 changes: 10 additions & 11 deletions src/Disposable/RefCountDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

class RefCountDisposable implements DisposableInterface
{
private $count = 0;
private $disposable;
private $isDisposed = false;
private $isPrimaryDisposed = false;

public function __construct(DisposableInterface $disposable)
{
$this->disposable = $disposable;
public function __construct(
private readonly DisposableInterface $disposable,
private int $count = 0,
private bool $isDisposed = false,
private bool $isPrimaryDisposed = false
) {
}

public function dispose()
public function dispose(): void
{
if ($this->isDisposed) {
return;
Expand All @@ -32,13 +31,13 @@ public function dispose()
}
}

public function getDisposable()
public function getDisposable(): DisposableInterface|CallbackDisposable
{
if (!$this->isDisposed) {
return $this->createInnerDisposable();
}

return new CallbackDisposable(function () {
return new CallbackDisposable(function (): void {
}); // no op
}

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

return new CallbackDisposable(function () use (&$isInnerDisposed) {
return new CallbackDisposable(function () use (&$isInnerDisposed): void {
if ($this->isDisposed()) {
return;
}
Expand Down
22 changes: 7 additions & 15 deletions src/Disposable/ScheduledDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@

class ScheduledDisposable implements DisposableInterface
{
/** @var DisposableInterface */
private $disposable;

/** @var SchedulerInterface */
private $scheduler;

/** @var bool */
protected $isDisposed = false;

public function __construct(SchedulerInterface $scheduler, DisposableInterface $disposable)
{
$this->scheduler = $scheduler;
$this->disposable = $disposable;
public function __construct(
private SchedulerInterface $scheduler,
private DisposableInterface $disposable,
protected bool $isDisposed = false
) {
}

public function dispose()
public function dispose(): void
{
if ($this->isDisposed) {
return;
}

$this->isDisposed = true;

$this->scheduler->schedule(function () {
$this->scheduler->schedule(function (): void {
$this->disposable->dispose();
});
}
Expand Down
22 changes: 5 additions & 17 deletions src/Disposable/SerialDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@

use Rx\DisposableInterface;

/**
* Class SerialDisposable
* @package Rx\Disposable
*/
class SerialDisposable implements DisposableInterface
{
/** @var bool */
private $isDisposed = false;
private bool $isDisposed = false;

/** @var DisposableInterface */
private $disposable = null;
private ?DisposableInterface $disposable = null;

public function dispose()
public function dispose(): void
{
if ($this->isDisposed) {
return;
Expand All @@ -33,18 +27,12 @@ public function dispose()
}
}

/**
* @return DisposableInterface
*/
public function getDisposable()
public function getDisposable(): null|DisposableInterface
{
return $this->disposable;
}

/**
* @param DisposableInterface $disposable
*/
public function setDisposable(DisposableInterface $disposable)
public function setDisposable(DisposableInterface $disposable): void
{
$shouldDispose = $this->isDisposed;

Expand Down
12 changes: 6 additions & 6 deletions src/Disposable/SingleAssignmentDisposable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

class SingleAssignmentDisposable implements DisposableInterface
{
private $current;
private $isDisposed = false;
private null|DisposableInterface $current = null;
private bool $isDisposed = false;

public function dispose()
public function dispose(): void
{
$old = null;

Expand All @@ -27,7 +27,7 @@ public function dispose()
}
}

public function setDisposable(DisposableInterface $disposable = null)
public function setDisposable(DisposableInterface $disposable = null): void
{
if ($this->current) {
throw new RuntimeException('Disposable has already been assigned.');
Expand All @@ -42,12 +42,12 @@ public function setDisposable(DisposableInterface $disposable = null)
}
}

public function getDisposable()
public function getDisposable(): null|DisposableInterface
{
return $this->current;
}

public function isDisposed()
public function isDisposed(): bool
{
return $this->isDisposed;
}
Expand Down
8 changes: 3 additions & 5 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@
*/
abstract class Notification
{
private $kind;

/**
* @param mixed $kind Kind of notification
*/
public function __construct($kind)
public function __construct(private $kind)
{
$this->kind = $kind;
}

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

return;
return null;
}

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

public function equals($other): bool
{
return (string)$this === (string)$other;
return (string) $this === (string)$other;
}

abstract protected function doAcceptObservable(ObserverInterface $observer);
Expand Down
2 changes: 1 addition & 1 deletion src/Notification/OnErrorNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class OnErrorNotification extends Notification
{
private $exception;
private \Throwable $exception;

public function __construct(\Throwable $exception)
{
Expand Down
Loading

0 comments on commit 788e535

Please sign in to comment.