Skip to content

Commit fbbff2e

Browse files
authored
chore: fix static analysis (#474)
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent a6e87b6 commit fbbff2e

File tree

10 files changed

+29
-21
lines changed

10 files changed

+29
-21
lines changed

docs/component/str-byte.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- [contains_ci](./../../src/Psl/Str/Byte/contains_ci.php#L21)
3131
- [ends_with](./../../src/Psl/Str/Byte/ends_with.php#L12)
3232
- [ends_with_ci](./../../src/Psl/Str/Byte/ends_with_ci.php#L14)
33-
- [length](./../../src/Psl/Str/Byte/length.php#L14)
33+
- [length](./../../src/Psl/Str/Byte/length.php#L16)
3434
- [lowercase](./../../src/Psl/Str/Byte/lowercase.php#L14)
3535
- [ord](./../../src/Psl/Str/Byte/ord.php#L12)
3636
- [pad_left](./../../src/Psl/Str/Byte/pad_left.php#L24)

docs/component/str-grapheme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [contains_ci](./../../src/Psl/Str/Grapheme/contains_ci.php#L22)
2525
- [ends_with](./../../src/Psl/Str/Grapheme/ends_with.php#L16)
2626
- [ends_with_ci](./../../src/Psl/Str/Grapheme/ends_with_ci.php#L16)
27-
- [length](./../../src/Psl/Str/Grapheme/length.php#L18)
27+
- [length](./../../src/Psl/Str/Grapheme/length.php#L20)
2828
- [range](./../../src/Psl/Str/Grapheme/range.php#L43)
2929
- [reverse](./../../src/Psl/Str/Grapheme/reverse.php#L16)
3030
- [search](./../../src/Psl/Str/Grapheme/search.php#L27)

src/Psl/Iter/Iterator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ public function rewind(): void
164164
/**
165165
* Seek to the given position.
166166
*
167-
* @param int<0, max> $offset
167+
* @param int<0, max> $position
168168
*
169169
* @throws Exception\OutOfBoundsException If $position is out-of-bounds.
170170
*/
171-
public function seek(int $offset): void
171+
public function seek(int $position): void
172172
{
173-
if ($offset <= $this->position) {
174-
$this->position = $offset;
173+
if ($position <= $this->position) {
174+
$this->position = $position;
175175
return;
176176
}
177177

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

189189
return;
190190
}
191191

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

196-
$this->position = $offset;
196+
$this->position = $position;
197197
}
198198

199199
/**

src/Psl/Str/Byte/compare.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* Returns < 0 if `$string1` is less than `$string2`, > 0 if `$string1` is
1212
* greater than `$string2`, and 0 if they are equal.
1313
*
14-
* @param int|null $length number of characters to use in the comparison,
15-
* or null to compare the whole string
14+
* @param int<0, max>|null $length number of characters to use in the comparison,
15+
* or null to compare the whole string
1616
*
1717
* @pure
1818
*/

src/Psl/Str/Byte/compare_ci.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*
1414
* @pure
1515
*
16-
* @param int|null $length number of characters to use in the comparison,
17-
* or null to compare the whole string
16+
* @param int<0, max>|null $length number of characters to use in the comparison,
17+
* or null to compare the whole string
1818
*/
1919
function compare_ci(string $string, string $other, ?int $length = null): int
2020
{

src/Psl/Str/Byte/length.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* Returns the length of the given string, i.e. the number of bytes.
1111
*
12+
* @return int<0, max>
13+
*
1214
* @pure
1315
*/
1416
function length(string $string): int

src/Psl/Str/Byte/strip_suffix.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function strip_suffix(string $string, string $suffix): string
3535
/**
3636
* $string_length is greater than $suffix_length, so the result is always int<0, max>.
3737
*
38-
* @psalm-suppress ArgumentTypeCoercion
38+
* @var int<0, max> $length
3939
*/
40-
return slice($string, 0, $string_length - $suffix_length);
40+
$length = $string_length - $suffix_length;
41+
42+
return slice($string, 0, $length);
4143
}

src/Psl/Str/Grapheme/length.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
/**
1212
* Returns the length of the given string in grapheme units.
1313
*
14-
* @pure
15-
*
1614
* @throws Exception\InvalidArgumentException If $string is not made of grapheme clusters.
15+
*
16+
* @return int<0, max>
17+
*
18+
* @pure
1719
*/
1820
function length(string $string): int
1921
{

src/Psl/Str/Grapheme/strip_suffix.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function strip_suffix(string $string, string $suffix): string
3939
/**
4040
* $string_length is greater than $suffix_length, so the result is always int<0, max>.
4141
*
42-
* @psalm-suppress ArgumentTypeCoercion
42+
* @var int<0, max> $length
4343
*/
44-
return slice($string, 0, $string_length - $suffix_length);
44+
$length = $string_length - $suffix_length;
45+
46+
return slice($string, 0, $length);
4547
}

src/Psl/Str/length.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* Str\length('تونس')
2121
* => Int(4)
2222
*
23-
* @pure
24-
*
2523
* @return int<0, max>
24+
*
25+
* @pure
2626
*/
2727
function length(string $string, Encoding $encoding = Encoding::Utf8): int
2828
{

0 commit comments

Comments
 (0)