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 Sep 29, 2024
1 parent 50152f5 commit 0901135
Show file tree
Hide file tree
Showing 104 changed files with 694 additions and 1,323 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
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
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
10 changes: 3 additions & 7 deletions src/Notification/OnNextNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

class OnNextNotification extends Notification
{
private $value;

public function __construct($value)
public function __construct(private $value)
{
parent::__construct('N');

Expand All @@ -35,10 +33,8 @@ public function __toString(): string

public function equals($other): bool
{
if (($other instanceof $this) && is_object($this->value) && is_object($other->value)) {
if ($this->value instanceof $other->value && method_exists($this->value, "equals")) {
return $this->value->equals($other->value);
}
if (($other instanceof $this) && is_object($this->value) && is_object($other->value) && ($this->value instanceof $other->value && method_exists($this->value, "equals"))) {
return $this->value->equals($other->value);
}

return (string)$this === (string)$other;
Expand Down
Loading

0 comments on commit 0901135

Please sign in to comment.