Skip to content

Commit

Permalink
Add more specific psalm type for result of `StringHelper::base64UrlEn…
Browse files Browse the repository at this point in the history
…code()` method (#128)
  • Loading branch information
vjik authored Mar 17, 2024
1 parent 1ffc263 commit da1a178
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.4.1 under development

- no changes in this release.
- Enh #128: Add more specific psalm type for result of `StringHelper::base64UrlEncode()` method (@vjik)

## 2.4.0 December 22, 2023

Expand Down
4 changes: 4 additions & 0 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ public static function uppercaseFirstCharacterInEachWord(string $string, string
* @param string $input The string to encode.
*
* @return string Encoded string.
*
* @psalm-template T as string
* @psalm-param T $input
* @psalm-return (T is non-empty-string ? non-empty-string : "")
*/
public static function base64UrlEncode(string $input): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,14 @@ public function testBase64UrlDecode($output, $base64UrlEncoded): void
$this->assertEquals($output, $decoded);
}

public function base64UrlEncodedStringsProvider(): array
public static function base64UrlEncodedStringsProvider(): array
{
return [
'Regular string' => ['This is an encoded string', 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw=='],
'? and _ characters' => ['subjects?_d=1', 'c3ViamVjdHM_X2Q9MQ=='],
'> character' => ['subjects>_d=1', 'c3ViamVjdHM-X2Q9MQ=='],
'Unicode' => ['Это закодированная строка', '0K3RgtC-INC30LDQutC-0LTQuNGA0L7QstCw0L3QvdCw0Y8g0YHRgtGA0L7QutCw'],
'empty string' => ['', ''],
];
}

Expand Down

0 comments on commit da1a178

Please sign in to comment.