Skip to content
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

[5.1] Add PHP 8.4 to CI #126

Merged
merged 3 commits into from
Jul 25, 2024
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- php-versions: '7.1'
coverage: 'none'
code-analysis: 'yes'
- php-versions: '8.4'
coverage: 'pcov'
code-analysis: 'yes'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -49,7 +52,7 @@ jobs:

- name: Code Analysis (PHP CS-Fixer)
if: matrix.code-analysis == 'yes'
run: php vendor/bin/php-cs-fixer fix --dry-run --diff
run: PHP_CS_FIXER_IGNORE_ENV=true php vendor/bin/php-cs-fixer fix --dry-run --diff

- name: Code Analysis (PHPStan)
if: matrix.code-analysis == 'yes'
Expand Down
4 changes: 2 additions & 2 deletions lib/EmitterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function once(string $eventName, callable $callBack, int $priority = 100)
* Lastly, if there are 5 event handlers for an event. The continueCallback
* will be called at most 4 times.
*/
public function emit(string $eventName, array $arguments = [], callable $continueCallBack = null): bool;
public function emit(string $eventName, array $arguments = [], ?callable $continueCallBack = null): bool;

/**
* Returns the list of listeners for an event.
Expand All @@ -74,5 +74,5 @@ public function removeListener(string $eventName, callable $listener): bool;
* removed. If it is not specified, every listener for every event is
* removed.
*/
public function removeAllListeners(string $eventName = null);
public function removeAllListeners(?string $eventName = null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these kind of changes, if someone was implementing this interface, and has string $eventName = null and we change this "underneath them" adding the ?, then will their code work unchanged?

LSP is not broken - the old and new interface, and the implementation of the interface all have exactly the same set of allowable things that can be passed in the parameter.

I wonder if this will break anything for anyone (e.g. in older versions of PHP) (callers will be fine - now it is explicit that they can pass null)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the following code in both PHP 7.4 and PHP 8.3 and it does not trigger any error.

interface TestI {
    public function test(?string $a = null);
}
class Cls implements TestI {
    public function test(string $a = null) {}
}

}
4 changes: 2 additions & 2 deletions lib/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function once(string $eventName, callable $callBack, int $priority = 100)
* Lastly, if there are 5 event handlers for an event. The continueCallback
* will be called at most 4 times.
*/
public function emit(string $eventName, array $arguments = [], callable $continueCallBack = null): bool
public function emit(string $eventName, array $arguments = [], ?callable $continueCallBack = null): bool
{
if (\is_null($continueCallBack)) {
foreach ($this->listeners($eventName) as $listener) {
Expand Down Expand Up @@ -160,7 +160,7 @@ public function removeListener(string $eventName, callable $listener): bool
* removed. If it is not specified, every listener for every event is
* removed.
*/
public function removeAllListeners(string $eventName = null)
public function removeAllListeners(?string $eventName = null)
{
if (!\is_null($eventName)) {
unset($this->listeners[$eventName]);
Expand Down
6 changes: 3 additions & 3 deletions lib/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Promise
* Each are callbacks that map to $this->fulfill and $this->reject.
* Using the executor is optional.
*/
public function __construct(callable $executor = null)
public function __construct(?callable $executor = null)
{
if ($executor) {
$executor(
Expand Down Expand Up @@ -87,7 +87,7 @@ public function __construct(callable $executor = null)
* If either of the callbacks throw an exception, the returned promise will
* be rejected and the exception will be passed back.
*/
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): Promise
{
// This new subPromise will be returned from this function, and will
// be fulfilled with the result of the onFulfilled or onRejected event
Expand Down Expand Up @@ -220,7 +220,7 @@ public function wait()
* correctly, and any chained promises are also correctly fulfilled or
* rejected.
*/
private function invokeCallback(Promise $subPromise, callable $callBack = null)
private function invokeCallback(Promise $subPromise, ?callable $callBack = null)
{
// We use 'nextTick' to ensure that the event handlers are always
// triggered outside of the calling stack in which they were originally
Expand Down
4 changes: 2 additions & 2 deletions lib/WildcardEmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function once(string $eventName, callable $callBack, int $priority = 100)
* Lastly, if there are 5 event handlers for an event. The continueCallback
* will be called at most 4 times.
*/
public function emit(string $eventName, array $arguments = [], callable $continueCallBack = null): bool
public function emit(string $eventName, array $arguments = [], ?callable $continueCallBack = null): bool
{
if (\is_null($continueCallBack)) {
foreach ($this->listeners($eventName) as $listener) {
Expand Down Expand Up @@ -195,7 +195,7 @@ public function removeListener(string $eventName, callable $listener): bool
* removed. If it is not specified, every listener for every event is
* removed.
*/
public function removeAllListeners(string $eventName = null)
public function removeAllListeners(?string $eventName = null)
{
if (\is_null($eventName)) {
$this->listeners = [];
Expand Down