Skip to content

Commit

Permalink
manual updates/fixes after code refactoring with Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Dec 8, 2023
1 parent 904d744 commit 4f381f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 55 deletions.
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,3 @@ services:

volumes:
wordpress:

networks:
default:
name: swoole-library-network
28 changes: 8 additions & 20 deletions src/core/MultibyteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/core/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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})");
Expand Down
33 changes: 9 additions & 24 deletions src/core/StringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

class StringObject implements \Stringable
{
/**
* @var string
*/
protected $string;
protected string $string;

/**
* StringObject constructor.
Expand All @@ -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);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/Coroutine/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 4f381f0

Please sign in to comment.