Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ parameters:
- ../stubs/file.stub
- ../stubs/stream_socket_client.stub
- ../stubs/stream_socket_server.stub
- ../stubs/ctype.stub
earlyTerminatingMethodCalls: []
earlyTerminatingFunctionCalls: []
resultCachePath: %tmpDir%/resultCache.php
Expand Down
51 changes: 51 additions & 0 deletions stubs/ctype.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @phpstan-assert-if-true =($text is string ? non-empty-string : int) $text
*/
function ctype_alnum(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_alpha(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_cntrl(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_lower(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-empty-string : int) $text
*/
function ctype_graph(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-empty-string : int) $text
*/
function ctype_print(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_punct(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_space(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-falsy-string : int) $text
*/
function ctype_upper(mixed $text): bool {}

/**
* @phpstan-assert-if-true =($text is string ? non-empty-string : int) $text
*/
function ctype_xdigit(mixed $text): bool {}
151 changes: 151 additions & 0 deletions tests/PHPStan/Analyser/nsrt/ctype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

declare(strict_types=1);

namespace Ctype;

use function ctype_alnum;
use function ctype_alpha;
use function ctype_cntrl;
use function ctype_graph;
use function ctype_lower;
use function ctype_print;
use function ctype_punct;
use function ctype_space;
use function ctype_upper;
use function ctype_xdigit;
use function PHPStan\Testing\assertType;

function test(string $str): void
{
// functions asserting non-falsy-string

if (ctype_alpha($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

if (ctype_cntrl($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

if (ctype_lower($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

if (ctype_upper($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

if (ctype_punct($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

if (ctype_space($str)) {
assertType('non-falsy-string', $str);
} else {
assertType('string', $str);
}

// functions asserting non-empty-string
// ctype_digit is tested in another file

if (ctype_alnum($str)) {
assertType('non-empty-string', $str);
} else {
assertType('string', $str);
}

if (ctype_graph($str)) {
assertType('non-empty-string', $str);
} else {
assertType('string', $str);
}

if (ctype_print($str)) {
assertType('non-empty-string', $str);
} else {
assertType('string', $str);
}

if (ctype_xdigit($str)) {
assertType('non-empty-string', $str);
} else {
assertType('string', $str);
}
}

function testInt(int $int): void
{
if (ctype_alpha($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_cntrl($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_lower($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_upper($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_punct($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_space($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

// functions asserting non-empty-string
// ctype_digit is tested in another file

if (ctype_alnum($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_graph($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_print($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}

if (ctype_xdigit($int)) {
assertType('int', $int);
} else {
assertType('int', $int);
}
}
Loading