Skip to content

PHP 8.4 #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"require-dev": {
"satooshi/php-coveralls": "~1.0",
"phpunit/phpunit": "^8.5 || ^9",
"react/event-loop": "^1.0 || ^0.5 || ^0.4.2"
"react/event-loop": "^1.0 || ^0.5 || ^0.4.2",
"rector/rector": "^2.0"
},
"suggest": {
"react/event-loop": "Used for scheduling async operations"
Expand Down
8 changes: 4 additions & 4 deletions demo/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function asString($value) {

$createStdoutObserver = function ($prefix = '') {
return new Rx\Observer\CallbackObserver(
function ($value) use ($prefix) { echo $prefix . "Next value: " . asString($value) . "\n"; },
function ($error) use ($prefix) { echo $prefix . "Exception: " . $error->getMessage() . "\n"; },
function () use ($prefix) { echo $prefix . "Complete!\n"; }
function ($value) use ($prefix): void { echo $prefix . "Next value: " . asString($value) . "\n"; },
function ($error) use ($prefix): void { echo $prefix . "Exception: " . $error->getMessage() . "\n"; },
function () use ($prefix): void { echo $prefix . "Complete!\n"; }
);
};

Expand All @@ -42,6 +42,6 @@ function () use ($prefix) { echo $prefix . "Complete!\n"; }
Scheduler::setDefaultFactory(function () use ($loop) {
return new Scheduler\EventLoopScheduler($loop);
});
register_shutdown_function(function () use ($loop) {
register_shutdown_function(function () use ($loop): void {
$loop->run();
});
2 changes: 1 addition & 1 deletion demo/create/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$observer->onNext(42);
$observer->onCompleted();

return new CallbackDisposable(function () {
return new CallbackDisposable(function (): void {
echo "Disposed\n";
});
});
Expand Down
2 changes: 1 addition & 1 deletion demo/create/createObservable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$observer->onNext(42);
$observer->onCompleted();

return new CallbackDisposable(function () {
return new CallbackDisposable(function (): void {
echo "Disposed\n";
});
});
Expand Down
2 changes: 1 addition & 1 deletion demo/custom-operator/Rot13Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Rot13Operator implements OperatorInterface
public function __invoke(ObservableInterface $observable, ObserverInterface $observer): DisposableInterface
{
return $observable->subscribe(
function ($json) use ($observer) {
function ($json) use ($observer): void {
$observer->onNext(str_rot13($json));
},
[$observer, 'onError'],
Expand Down
2 changes: 1 addition & 1 deletion demo/delay/delay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once __DIR__ . '/../bootstrap.php';

\Rx\Observable::interval(1000)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo 'Side effect: ' . $x . "\n";
})
->delay(500)
Expand Down
6 changes: 3 additions & 3 deletions demo/do/do.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

$source = \Rx\Observable::range(0, 3)
->do(
function ($x) {
function ($x): void {
echo 'Do Next:', $x, PHP_EOL;
},
function (Throwable $err) {
function (Throwable $err): void {
echo 'Do Error:', $err->getMessage(), PHP_EOL;
},
function () {
function (): void {
echo 'Do Completed', PHP_EOL;
}
);
Expand Down
2 changes: 1 addition & 1 deletion demo/do/doOnCompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . '/../bootstrap.php';

$source = \Rx\Observable::empty()
->doOnCompleted(function () {
->doOnCompleted(function (): void {
echo 'Do Completed', PHP_EOL;
});

Expand Down
2 changes: 1 addition & 1 deletion demo/do/doOnError.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . '/../bootstrap.php';

$source = \Rx\Observable::error(new Exception('Oops'))
->doOnError(function (Throwable $err) {
->doOnError(function (Throwable $err): void {
echo 'Do Error:', $err->getMessage(), PHP_EOL;
});

Expand Down
2 changes: 1 addition & 1 deletion demo/do/doOnNext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . '/../bootstrap.php';

$source = \Rx\Observable::range(0, 3)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo 'Do Next:', $x, PHP_EOL;
});

Expand Down
2 changes: 1 addition & 1 deletion demo/finally/finally-error.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
return $value;
})
->finally(function() {
->finally(function(): void {
echo "Finally\n";
})
->subscribe($stdoutObserver);
2 changes: 1 addition & 1 deletion demo/finally/finally.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once __DIR__ . '/../bootstrap.php';

Rx\Observable::range(1, 3)
->finally(function() {
->finally(function(): void {
echo "Finally\n";
})
->subscribe($stdoutObserver);
2 changes: 1 addition & 1 deletion demo/groupBy/groupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ function ($key) {
return $key;
}
)
->subscribe(function ($groupedObserver) use ($createStdoutObserver) {
->subscribe(function ($groupedObserver) use ($createStdoutObserver): void {
$groupedObserver->subscribe($createStdoutObserver($groupedObserver->getKey() . ": "));
});
8 changes: 4 additions & 4 deletions demo/groupBy/groupByUntil.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ function ($x) {
});

$subscription = $source->subscribe(new CallbackObserver(
function (\Rx\Observable $obs) {
function (\Rx\Observable $obs): void {
// Print the count
$obs->count()->subscribe(new CallbackObserver(
function ($x) {
function ($x): void {
echo 'Count: ', $x, PHP_EOL;
}));
},
function (Throwable $err) {
function (Throwable $err): void {
echo 'Error', $err->getMessage(), PHP_EOL;
},
function () {
function (): void {
echo 'Completed', PHP_EOL;
}));

2 changes: 1 addition & 1 deletion demo/promise/toPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
$promise = \Rx\Observable::of(42)
->toPromise();

$promise->then(function ($value) {
$promise->then(function ($value): void {
echo "Value: {$value}\n";
});
2 changes: 1 addition & 1 deletion demo/publish/publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

$source = $interval
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo "Side effect\n";
});

Expand Down
2 changes: 1 addition & 1 deletion demo/publish/publishLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$source = $range
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo "Side effect\n";
});

Expand Down
2 changes: 1 addition & 1 deletion demo/publish/publishValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$source = $range
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo "Side effect\n";
});

Expand Down
6 changes: 3 additions & 3 deletions demo/recursive-scheduler/recursive-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($value)

public function _subscribe(\Rx\ObserverInterface $observer): \Rx\DisposableInterface
{
return \Rx\Scheduler::getDefault()->scheduleRecursive(function ($reschedule) use ($observer) {
return \Rx\Scheduler::getDefault()->scheduleRecursive(function ($reschedule) use ($observer): void {
$observer->onNext($this->value);
$reschedule();
});
Expand All @@ -31,14 +31,14 @@ public function _subscribe(\Rx\ObserverInterface $observer): \Rx\DisposableInter
$observable = new RecursiveReturnObservable(21);
$disposable = $observable->subscribe($stdoutObserver);

Loop::repeat(100, function () {
Loop::repeat(100, function (): void {
$memory = memory_get_usage() / 1024;
$formatted = number_format($memory, 3) . 'K';
echo "Current memory usage: {$formatted}\n";
});

// after a second we'll dispose the 21 observable
Loop::delay(1000, function () use ($disposable) {
Loop::delay(1000, function () use ($disposable): void {
echo "Disposing 21 observable.\n";
$disposable->dispose();
});
Expand Down
2 changes: 1 addition & 1 deletion demo/repeat/repeatWhen.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
return $acc + $x;
}, 0)
->delay(1000)
->doOnNext(function () {
->doOnNext(function (): void {
echo "1 second delay", PHP_EOL;
})
->takeWhile(function ($count) {
Expand Down
2 changes: 1 addition & 1 deletion demo/replay/replay.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$source = $interval
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo $x, ' something', PHP_EOL;
echo 'Side effect', PHP_EOL;
});
Expand Down
2 changes: 1 addition & 1 deletion demo/share/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//With Share
$source = \Rx\Observable::interval(1000)
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo "Side effect\n";
});

Expand Down
2 changes: 1 addition & 1 deletion demo/share/shareReplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$source = $interval
->take(4)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo 'Side effect', PHP_EOL;
});

Expand Down
2 changes: 1 addition & 1 deletion demo/share/shareValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$source = \Rx\Observable::interval(1000)
->take(2)
->doOnNext(function ($x) {
->doOnNext(function ($x): void {
echo "Side effect\n";
});

Expand Down
4 changes: 2 additions & 2 deletions demo/share/singleInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$source = $interval
->take(2)
->do(function () {
->do(function (): void {
echo 'Side effect', PHP_EOL;
});

Expand All @@ -16,7 +16,7 @@
$single->subscribe($createStdoutObserver('SourceA '));
$single->subscribe($createStdoutObserver('SourceB '));

\Rx\Observable::timer(5000)->subscribe(function () use ($single, &$createStdoutObserver) {
\Rx\Observable::timer(5000)->subscribe(function () use ($single, &$createStdoutObserver): void {
// resubscribe two times again, more than 5 seconds later,
// long after the original two subscriptions have ended
$single->subscribe($createStdoutObserver('SourceC '));
Expand Down
4 changes: 2 additions & 2 deletions demo/subscribeOn/subscribeOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
$loop = Factory::create();

$observable = Rx\Observable::create(function (ObserverInterface $observer) use ($loop) {
$handler = function () use ($observer) {
$handler = function () use ($observer): void {
$observer->onNext(42);
$observer->onCompleted();
};

// Change scheduler for here
$timer = $loop->addTimer(0.001, $handler);

return new CallbackDisposable(function () use ($loop, $timer) {
return new CallbackDisposable(function () use ($loop, $timer): void {
// And change scheduler for here
if ($timer) {
$loop->cancelTimer($timer);
Expand Down
4 changes: 2 additions & 2 deletions demo/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function run_cmd($file) {
$output,
$exit_code
);
return array($exit_code, implode("\n", $output));
return [$exit_code, implode("\n", $output)];
}

function run_demo($file) {
Expand Down Expand Up @@ -38,7 +38,7 @@ function has_expect($file) {
}

function strip_cwd($cwd, $absolute_path) {
$is_prefix = 0 === strpos($absolute_path, $cwd);
$is_prefix = str_starts_with($absolute_path, $cwd);
if (!$is_prefix) {
return $absolute_path;
}
Expand Down
2 changes: 1 addition & 1 deletion demo/toArray/toArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

$subscription = $source->toArray()
->subscribe(new CallbackObserver(
function ($array) use ($observer) {
function ($array) use ($observer): void {
$observer->onNext(json_encode($array));
},
[$observer, "onError"],
Expand Down
2 changes: 1 addition & 1 deletion demo/zip/zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$subscription = $source
->subscribe(new CallbackObserver(
function ($array) use ($observer) {
function ($array) use ($observer): void {
$observer->onNext(json_encode($array));
},
[$observer, 'onError'],
Expand Down
10 changes: 5 additions & 5 deletions docs/build-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
require_once __DIR__ . '/doc-writer.php';
require_once __DIR__ . '/utils.php';

function println($line) {
function println($line): void {
$args = func_get_args();
echo call_user_func_array('sprintf', $args) . "\n";
}

function run_lint() {
function run_lint(): void {
$docs = load_all_docs();
println("Successfully loaded documentation for %d observables/operators\n",
count($docs)
Expand All @@ -33,7 +33,7 @@ function run_lint() {
exit(0);
}

function run_reactivex() {
function run_reactivex(): void {
$allDocs = load_all_docs();

$docs = array_filter($allDocs, function ($doc) {
Expand Down Expand Up @@ -74,14 +74,14 @@ function($item) { return $item->reactivexId; }
exit(0);
}

function run_usage() {
function run_usage(): void {
println("Usage: $argv[0] <command>");
println(" lint Verifies that documentation can be loaded");
println(" reactivex Updates the reactivex documentation");
exit(1);
}

function main($argv) {
function main($argv): void {
if (count($argv) !== 2) {
run_usage();
}
Expand Down
2 changes: 1 addition & 1 deletion docs/doc-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function has_documentation_tag(\ReflectionMethod $method) {
}

function load_all_docs() {
$observable = new \ReflectionClass('Rx\Observable');
$observable = new \ReflectionClass(\Rx\Observable::class);

$possibleMethods = $observable
->getMethods(ReflectionMethod::IS_STATIC|ReflectionMethod::IS_PUBLIC);
Expand Down
Loading