Skip to content

Commit

Permalink
Support non-empty-string in str_shuffle()
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Nov 7, 2023
1 parent d875a42 commit 0205282
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stubs/core.stub
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function base64_encode(string $string) : string {}
*/
function bin2hex(string $string): string {}

/**
* @return ($string is non-empty-string ? non-empty-string : string)
*/
function str_shuffle(string $string): string {}

/**
* @param array<mixed> $result
* @param-out array<int|string, array|string> $result
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-9803.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-connection-fns.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9963.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/str-shuffle.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9995.php');
}

Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/data/str-shuffle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace StrShuffle;

use function PHPStan\Testing\assertType;

class X {
const ABC = 'abcdef';

/**
* @param non-empty-string $nonES
*/
function doFoo(string $s, $nonES):void {
assertType('non-empty-string', str_shuffle(self::ABC));
assertType('non-empty-string', str_shuffle('abc'));
assertType('string', str_shuffle($s));
assertType('non-empty-string', str_shuffle($nonES));
}
}

0 comments on commit 0205282

Please sign in to comment.