diff --git a/docker-compose.yml b/docker-compose.yml index d507bc4..b4ee982 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -90,7 +90,3 @@ services: volumes: wordpress: - -networks: - default: - name: swoole-library-network diff --git a/src/core/MultibyteStringObject.php b/src/core/MultibyteStringObject.php index e45b847..fc15654 100644 --- a/src/core/MultibyteStringObject.php +++ b/src/core/MultibyteStringObject.php @@ -18,36 +18,24 @@ public function length(): int return mb_strlen($this->string); } - /** - * @return false|int - */ - public function indexOf(string $needle, int $offset = 0, ?string $encoding = null) + public function indexOf(string $needle, int $offset = 0, ?string $encoding = null): false|int { - return mb_strpos($this->string, ...func_get_args()); + return mb_strpos($this->string, $needle, $offset, $encoding); } - /** - * @return false|int - */ - public function lastIndexOf(string $needle, int $offset = 0, ?string $encoding = null) + public function lastIndexOf(string $needle, int $offset = 0, ?string $encoding = null): false|int { - return mb_strrpos($this->string, ...func_get_args()); + return mb_strrpos($this->string, $needle, $offset, $encoding); } - /** - * @return false|int - */ - public function pos(string $needle, int $offset = 0, ?string $encoding = null) + public function pos(string $needle, int $offset = 0, ?string $encoding = null): false|int { - return mb_strpos($this->string, ...func_get_args()); + return mb_strpos($this->string, $needle, $offset, $encoding); } - /** - * @return false|int - */ - public function rpos(string $needle, int $offset = 0, ?string $encoding = null) + public function rpos(string $needle, int $offset = 0, ?string $encoding = null): false|int { - return mb_strrpos($this->string, ...func_get_args()); + return mb_strrpos($this->string, $needle, $offset, $encoding); } /** diff --git a/src/core/NameResolver.php b/src/core/NameResolver.php index b21c9ca..488b643 100644 --- a/src/core/NameResolver.php +++ b/src/core/NameResolver.php @@ -77,7 +77,7 @@ public function lookup(string $name) /** * !!! The host MUST BE IP ADDRESS */ - protected function checkServerUrl(mixed $url) + protected function checkServerUrl(string $url) { $info = parse_url($url); if (empty($info['scheme']) or empty($info['host'])) { @@ -102,11 +102,7 @@ protected function checkServerUrl(mixed $url) $this->info = $info; } - /** - * @param $r ClientProxy - * @return bool - */ - protected function checkResponse($r, mixed $url) + protected function checkResponse(?ClientProxy $r, string $url): bool { if (empty($r)) { throw new Exception("failed to request URL({$url})"); diff --git a/src/core/StringObject.php b/src/core/StringObject.php index 44a1ce0..f3ef973 100644 --- a/src/core/StringObject.php +++ b/src/core/StringObject.php @@ -13,10 +13,7 @@ class StringObject implements \Stringable { - /** - * @var string - */ - protected $string; + protected string $string; /** * StringObject constructor. @@ -41,36 +38,24 @@ public function length(): int return strlen($this->string); } - /** - * @return false|int - */ - public function indexOf(string $needle, int $offset = 0) + public function indexOf(string $needle, int $offset = 0): false|int { - return strpos($this->string, ...(string) func_get_args()); + return strpos($this->string, $needle, $offset); } - /** - * @return false|int - */ - public function lastIndexOf(string $needle, int $offset = 0) + public function lastIndexOf(string $needle, int $offset = 0): false|int { - return strrpos($this->string, ...(string) func_get_args()); + return strrpos($this->string, $needle, $offset); } - /** - * @return false|int - */ - public function pos(string $needle, int $offset = 0) + public function pos(string $needle, int $offset = 0): false|int { - return strpos($this->string, ...(string) func_get_args()); + return strpos($this->string, $needle, $offset); } - /** - * @return false|int - */ - public function rpos(string $needle, int $offset = 0) + public function rpos(string $needle, int $offset = 0): false|int { - return strrpos($this->string, ...(string) func_get_args()); + return strrpos($this->string, $needle, $offset); } /** diff --git a/tests/unit/Coroutine/FunctionTest.php b/tests/unit/Coroutine/FunctionTest.php index 6298af4..e781a90 100644 --- a/tests/unit/Coroutine/FunctionTest.php +++ b/tests/unit/Coroutine/FunctionTest.php @@ -38,7 +38,11 @@ public function testBatchTimeout() }, ], 0.1); Runtime::setHookFlags(0); - self::assertEqualsWithDelta(microtime(true), $start + 0.11, 0.01, 'Tasks in the batch take about 0.10 to 0.12 second in total to finish.'); + self::assertThat( + microtime(true), + self::logicalAnd(self::greaterThan($start + 0.09), self::lessThan($start + 0.15)), + 'Tasks in the batch take 0.10+ second to finish.' + ); $this->assertEquals(count($results), 4); $this->assertEquals($results['gethostbyname'], gethostbyname('localhost'));