From c496dbdf0fa25fac7477dbf4c8060d014995f776 Mon Sep 17 00:00:00 2001 From: fagai Date: Wed, 25 Nov 2020 14:29:46 +0900 Subject: [PATCH 1/2] Supports void type return value --- Library/Stubs/Generator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Stubs/Generator.php b/Library/Stubs/Generator.php index 2719b3ebe9..0e39a01178 100644 --- a/Library/Stubs/Generator.php +++ b/Library/Stubs/Generator.php @@ -335,6 +335,11 @@ protected function buildMethod(ClassMethod $method, bool $isInterface, string $i $return = 'array'; ++$supported; } + + if (version_compare(PHP_VERSION, '7.1.0', '>=') && $method->areReturnTypesVoidCompatible()) { + $reutrn = 'void'; + ++$supported; + } if (!empty($return) && $method->areReturnTypesNullCompatible()) { if (version_compare(PHP_VERSION, '7.1.0', '>=')) { From 27a7e155cdf68aab8eaa64b8b306f522b3633c77 Mon Sep 17 00:00:00 2001 From: fagai Date: Wed, 25 Nov 2020 11:44:10 +0000 Subject: [PATCH 2/2] fixed --- Library/Stubs/Generator.php | 8 +- .../stubs/issues/expected/Issue_1900.zep.php | 4 +- .../issues/expected/Issue_1900_PHP70.zep.php | 134 ++++++++++++++++++ .../stubs/issues/expected/Issue_1986.zep.php | 2 +- .../issues/expected/Issue_1986_PHP70.zep.php | 31 ++++ tests/sharness/t0005-stubs.sh | 14 +- 6 files changed, 183 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/stubs/issues/expected/Issue_1900_PHP70.zep.php create mode 100644 tests/fixtures/stubs/issues/expected/Issue_1986_PHP70.zep.php diff --git a/Library/Stubs/Generator.php b/Library/Stubs/Generator.php index 0e39a01178..c7c08b2e34 100644 --- a/Library/Stubs/Generator.php +++ b/Library/Stubs/Generator.php @@ -335,11 +335,6 @@ protected function buildMethod(ClassMethod $method, bool $isInterface, string $i $return = 'array'; ++$supported; } - - if (version_compare(PHP_VERSION, '7.1.0', '>=') && $method->areReturnTypesVoidCompatible()) { - $reutrn = 'void'; - ++$supported; - } if (!empty($return) && $method->areReturnTypesNullCompatible()) { if (version_compare(PHP_VERSION, '7.1.0', '>=')) { @@ -353,7 +348,10 @@ protected function buildMethod(ClassMethod $method, bool $isInterface, string $i if ($supported > 1) { $return = ''; } + } elseif (version_compare(PHP_VERSION, '7.1.0', '>=') && $method->isVoid()) { + $return = 'void'; } + if (!empty($return)) { $return = ': '.$return; } diff --git a/tests/fixtures/stubs/issues/expected/Issue_1900.zep.php b/tests/fixtures/stubs/issues/expected/Issue_1900.zep.php index e3ef77abe2..16fbb38605 100644 --- a/tests/fixtures/stubs/issues/expected/Issue_1900.zep.php +++ b/tests/fixtures/stubs/issues/expected/Issue_1900.zep.php @@ -49,7 +49,7 @@ public function test01(): \StdClass * @param int $priority * @return void */ - public function attach(string $eventType, $handler, int $priority = 1) + public function attach(string $eventType, $handler, int $priority = 1): void { } @@ -71,7 +71,7 @@ public function arePrioritiesEnabled(): bool * @param mixed $handler * @return void */ - public function collectResponses(bool $collect, string $eventType, $handler) + public function collectResponses(bool $collect, string $eventType, $handler): void { } diff --git a/tests/fixtures/stubs/issues/expected/Issue_1900_PHP70.zep.php b/tests/fixtures/stubs/issues/expected/Issue_1900_PHP70.zep.php new file mode 100644 index 0000000000..e3ef77abe2 --- /dev/null +++ b/tests/fixtures/stubs/issues/expected/Issue_1900_PHP70.zep.php @@ -0,0 +1,134 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +class Issue_1900 implements AliasedManagerInterface +{ + + public $eventsManager; + + /** + * @var array $collect - descr for collect var. + */ + private $collect; + + + static protected $uniqueId = 0; + + + /** + * @return AliasedManagerInterface + */ + public function getEventsManager(): AliasedManagerInterface + { + } + + /** + * @return \StdClass + */ + public function test01(): \StdClass + { + } + + /** + * Attach a listener to the events manager + * + * @param object|callable $handler + * @param string $eventType + * @param int $priority + * @return void + */ + public function attach(string $eventType, $handler, int $priority = 1) + { + } + + /** + * Returns if priorities are enabled + * + * @return bool + */ + public function arePrioritiesEnabled(): bool + { + } + + /** + * Tells the event manager if it needs to collect all the responses returned + * by every registered listener in a single fire + * + * @param bool $collect + * @param string $eventType + * @param mixed $handler + * @return void + */ + public function collectResponses(bool $collect, string $eventType, $handler) + { + } + + /** + * Fires an event in the events manager causing the active listeners to be + * notified about it + * + * ```php + * $eventsManager->fire("db", $connection); + * ``` + * + * @param object $source + * @param mixed $data + * @return mixed + * @param string $eventType + * @param bool $cancelable + */ + public function fire(string $eventType, $source, $data = null, bool $cancelable = true) + { + } + + /** + * Internal handler to call a queue of events + * + * @return mixed + * @param SplPriorityQueue $queue + * @param \Psr\Http\Message\RequestInterface $event + */ + final public function fireQueue(SplPriorityQueue $queue, \Psr\Http\Message\RequestInterface $event): AliasedManagerInterface + { + } + + /** + * Returns all the attached listeners of a certain type + * + * @param string $type + * @return array + */ + public function getListeners(string $type): array + { + } + + /** + * @return resource + */ + public function getResources() + { + } + + /** + * Check whether certain type of event has listeners + * + * @param string $type + * @return AliasedManagerInterface + */ + public function hasListeners(string $type): AliasedManagerInterface + { + } + +} diff --git a/tests/fixtures/stubs/issues/expected/Issue_1986.zep.php b/tests/fixtures/stubs/issues/expected/Issue_1986.zep.php index 052dd6bb9a..ec985bae58 100644 --- a/tests/fixtures/stubs/issues/expected/Issue_1986.zep.php +++ b/tests/fixtures/stubs/issues/expected/Issue_1986.zep.php @@ -24,7 +24,7 @@ public function getEventsManager(): EventsManagerInterface * @param string $eventType * @return void */ - public function attach(string $eventType, $handler) + public function attach(string $eventType, $handler): void { } diff --git a/tests/fixtures/stubs/issues/expected/Issue_1986_PHP70.zep.php b/tests/fixtures/stubs/issues/expected/Issue_1986_PHP70.zep.php new file mode 100644 index 0000000000..052dd6bb9a --- /dev/null +++ b/tests/fixtures/stubs/issues/expected/Issue_1986_PHP70.zep.php @@ -0,0 +1,31 @@ +