Skip to content

Commit

Permalink
chore: fix static analysis
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed May 29, 2024
1 parent a6e87b6 commit 217364d
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/component/str-byte.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- [contains_ci](./../../src/Psl/Str/Byte/contains_ci.php#L21)
- [ends_with](./../../src/Psl/Str/Byte/ends_with.php#L12)
- [ends_with_ci](./../../src/Psl/Str/Byte/ends_with_ci.php#L14)
- [length](./../../src/Psl/Str/Byte/length.php#L14)
- [length](./../../src/Psl/Str/Byte/length.php#L16)
- [lowercase](./../../src/Psl/Str/Byte/lowercase.php#L14)
- [ord](./../../src/Psl/Str/Byte/ord.php#L12)
- [pad_left](./../../src/Psl/Str/Byte/pad_left.php#L24)
Expand Down
2 changes: 1 addition & 1 deletion docs/component/str-grapheme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- [contains_ci](./../../src/Psl/Str/Grapheme/contains_ci.php#L22)
- [ends_with](./../../src/Psl/Str/Grapheme/ends_with.php#L16)
- [ends_with_ci](./../../src/Psl/Str/Grapheme/ends_with_ci.php#L16)
- [length](./../../src/Psl/Str/Grapheme/length.php#L18)
- [length](./../../src/Psl/Str/Grapheme/length.php#L20)
- [range](./../../src/Psl/Str/Grapheme/range.php#L43)
- [reverse](./../../src/Psl/Str/Grapheme/reverse.php#L16)
- [search](./../../src/Psl/Str/Grapheme/search.php#L27)
Expand Down
14 changes: 7 additions & 7 deletions src/Psl/Iter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ public function rewind(): void
/**
* Seek to the given position.
*
* @param int<0, max> $offset
* @param int<0, max> $position
*
* @throws Exception\OutOfBoundsException If $position is out-of-bounds.
*/
public function seek(int $offset): void
public function seek(int $position): void
{
if ($offset <= $this->position) {
$this->position = $offset;
if ($position <= $this->position) {
$this->position = $position;
return;
}

Expand All @@ -184,16 +184,16 @@ public function seek(int $offset): void
$this->generator = null;
throw new Exception\OutOfBoundsException('Position is out-of-bounds.');
}
} while ($this->position < $offset);
} while ($this->position < $position);

return;
}

if ($offset >= $this->count()) {
if ($position >= $this->count()) {
throw new Exception\OutOfBoundsException('Position is out-of-bounds.');
}

$this->position = $offset;
$this->position = $position;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Str/Byte/compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* Returns < 0 if `$string1` is less than `$string2`, > 0 if `$string1` is
* greater than `$string2`, and 0 if they are equal.
*
* @param int|null $length number of characters to use in the comparison,
* or null to compare the whole string
* @param int<0, max>|null $length number of characters to use in the comparison,
* or null to compare the whole string
*
* @pure
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Psl/Str/Byte/compare_ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*
* @pure
*
* @param int|null $length number of characters to use in the comparison,
* or null to compare the whole string
* @param int<0, max>|null $length number of characters to use in the comparison,
* or null to compare the whole string
*/
function compare_ci(string $string, string $other, ?int $length = null): int
{
Expand Down
2 changes: 2 additions & 0 deletions src/Psl/Str/Byte/length.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Returns the length of the given string, i.e. the number of bytes.
*
* @return int<0, max>
*
* @pure
*/
function length(string $string): int
Expand Down
6 changes: 4 additions & 2 deletions src/Psl/Str/Byte/strip_suffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function strip_suffix(string $string, string $suffix): string
/**
* $string_length is greater than $suffix_length, so the result is always int<0, max>.
*
* @psalm-suppress ArgumentTypeCoercion
* @var int<0, max> $length
*/
return slice($string, 0, $string_length - $suffix_length);
$length = $string_length - $suffix_length;

return slice($string, 0, $length);
}
6 changes: 4 additions & 2 deletions src/Psl/Str/Grapheme/length.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
/**
* Returns the length of the given string in grapheme units.
*
* @pure
*
* @throws Exception\InvalidArgumentException If $string is not made of grapheme clusters.
*
* @return int<0, max>
*
* @pure
*/
function length(string $string): int
{
Expand Down
6 changes: 4 additions & 2 deletions src/Psl/Str/Grapheme/strip_suffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function strip_suffix(string $string, string $suffix): string
/**
* $string_length is greater than $suffix_length, so the result is always int<0, max>.
*
* @psalm-suppress ArgumentTypeCoercion
* @var int<0, max> $length
*/
return slice($string, 0, $string_length - $suffix_length);
$length = $string_length - $suffix_length;

return slice($string, 0, $length);
}
4 changes: 2 additions & 2 deletions src/Psl/Str/length.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* Str\length('تونس')
* => Int(4)
*
* @pure
*
* @return int<0, max>
*
* @pure
*/
function length(string $string, Encoding $encoding = Encoding::Utf8): int
{
Expand Down

0 comments on commit 217364d

Please sign in to comment.