Skip to content

Turn into PHPStan extension #5

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

Merged
merged 1 commit into from
Jan 4, 2025
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
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "react-parallel/stubs",
"description": "\ud83e\udecf Stubs (for PHPstan)",
"license": "MIT",
"type": "phpstan-extension",
"authors": [
{
"name": "Cees-Jan Kiewiet",
Expand All @@ -28,6 +29,13 @@
},
"sort-packages": true
},
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
}
},
"scripts": {
"post-install-cmd": [
"composer normalize"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
stubFiles:
- stubs/Channel.stub
- stubs/Event.stub
- stubs/functions.stub
- stubs/Future.stub
45 changes: 15 additions & 30 deletions stubs/Channel.stub
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

declare(strict_types=1);

namespace parallel;

/** @template T */
/**
* @template T
*/
final class Channel
{
/**
Expand All @@ -18,80 +18,65 @@ final class Channel
* Shall make an anonymous unbuffered channel
* Shall make an anonymous buffered channel with the given capacity
*
* @param int|null $capacity May be Channel::Infinite or a positive integer
* @param null|int $capacity May be Channel::Infinite or a positive integer
*/
public function __construct(int|null $capacity = null)
{
}
public function __construct(?int $capacity = null) {}

/* Access */

/**
* Shall make an unbuffered channel with the given name
* Shall make a buffered channel with the given name and capacity
*
* @param string $name The name of the channel.
* @param int|null $capacity May be Channel::Infinite or a positive integer
* @param string $name The name of the channel.
* @param null|int $capacity May be Channel::Infinite or a positive integer
*
* @return Channel<T>
*
* @throws Channel\Error\Existence if channel already exists.
*/
public static function make(string $name, int|null $capacity = null): Channel
{
}
public static function make(string $name, ?int $capacity = null): Channel {}

/**
* Shall open the channel with the given name
*
* @param string $name
* @return Channel<T>
*
* @throws Channel\Error\Existence if channel does not exist.
*/
public static function open(string $name): Channel
{
}
public static function open(string $name): Channel {}

/* Sharing */

/**
* Shall send the given value on this channel
*
* @param T $value
*
* @throws Channel\Error\Closed if channel is closed.
* @throws Channel\Error\IllegalValue if value is illegal.
*/
public function send($value): void
{
}
public function send($value): void {}

/**
* Shall recv a value from this channel
*
* @return T
*
* @throws Channel\Error\Closed if channel is closed.
*/
public function recv()
{
}
public function recv() {}

/* Closing */

/**
* Shall close this channel
*
* @throws Channel\Error\Closed if channel is closed.
*/
public function close(): void
{
}
public function close(): void {}

/**
* Returns name of channel
* @return string
*/
public function __toString(): string
{
}
public function __toString(): string {}
}
16 changes: 8 additions & 8 deletions stubs/Event.stub
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?php

declare(strict_types=1);

namespace parallel\Events;

use parallel\Channel;
use parallel\Future;

/** @template T */
/**
* @template T
*/
final class Event
{
/**
* Shall be one of Event\Type constants
* @var int
*/
public int $type;
public $type;

/**
* Shall be the source of the event (target name)
* @var string
*/
public string $source;
public $source;

/**
* Shall be either Future or Channel
*
* @var Future<T>|Channel<T>
*/
public Future|Channel $object;
public $object;

/**
* Shall be set for Read/Error events
*
* @var T
*/
public $value;
Expand Down
26 changes: 11 additions & 15 deletions stubs/Future.stub
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

declare(strict_types=1);

namespace parallel;

use Throwable;

/** @template T */
/**
* @template T
*/
final class Future
{
/* Resolution */
Expand All @@ -22,25 +22,21 @@ final class Future
* @throws Future\Error\Foreign if task raised an unrecognized uncaught exception.
* @throws Throwable Shall rethrow \Throwable uncaught in task
*/
public function value()
{
}
public function value() {}

/* State */

/**
* Shall indicate if the task is completed
* @return bool
*/
public function done(): bool
{
}
public function done(): bool {}

/**
* Shall indicate if the task was cancelled
* @return bool
*/
public function cancelled(): bool
{
}
public function cancelled(): bool {}

/* Cancellation */

Expand All @@ -49,10 +45,10 @@ final class Future
* Note: If task is running, it will be interrupted.
* Warning: Internal function calls in progress cannot be interrupted.
*
* @return bool
*
* @throws Future\Error\Killed if \parallel\Runtime executing task was killed.
* @throws Future\Error\Cancelled if task was already cancelled.
*/
public function cancel(): bool
{
}
public function cancel(): bool {}
}
Loading