Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-empty-string in str_shuffle() #2717

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
}
}