Skip to content

Commit

Permalink
Refactor: Rename parameter in method \Swoole\MultibyteStringObject::s…
Browse files Browse the repository at this point in the history
…ubstr() for consistency.
  • Loading branch information
deminy committed Feb 5, 2024
1 parent 1bc74de commit fce4670
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Changed:

* Refactor: Rename parameter in method `\Swoole\Database\PDOStatementProxy::setFetchMode()` for consistency.
* Refactor: Rename parameter in method `\Swoole\MultibyteStringObject::substr()` for consistency.
* Refactor: Enhance method `\Swoole\FastCGI\Message::withBody()` with explicit parameter type.

## 5.1.2 (2024-01-24)

Expand Down
9 changes: 3 additions & 6 deletions src/core/MultibyteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ public function ipos(string $needle, int $offset = 0, ?string $encoding = null):
}

/**
* @todo First parameter will be renamed to $start in Swoole 5.2+.
* @todo This method will be refactored and marked as final in Swoole 5.2+.
* 1. It should use keyword self instead of static.
* 2. Don't use function func_get_args().
* @see https://www.php.net/mb_substr
*/
public function substr(int $offset, ?int $length = null, ?string $encoding = null): static
public function substr(int $start, ?int $length = null, ?string $encoding = null): self
{
return new static(mb_substr($this->string, ...func_get_args())); // @phpstan-ignore new.static
return new self(mb_substr($this->string, $start, $length, $encoding));

Check failure on line 51 in src/core/MultibyteStringObject.php

View workflow job for this annotation

GitHub Actions / static-analysis

Method Swoole\MultibyteStringObject::substr() should return static(Swoole\MultibyteStringObject) but returns Swoole\MultibyteStringObject.
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/StringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function rtrim(): self
*/
public function substr(int $offset, ?int $length = null)
{
return new static(substr($this->string, ...func_get_args())); // @phpstan-ignore new.static
return new static(substr($this->string, $offset, $length)); // @phpstan-ignore new.static
}

public function repeat(int $times): static
Expand Down

0 comments on commit fce4670

Please sign in to comment.