Skip to content

Improve preg_split() function ReturnType #3757

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

Merged
merged 36 commits into from
May 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5784175
feat improve preg_split type Extension
malsuke Dec 25, 2024
e595e1e
feat add test for varibles
malsuke Dec 25, 2024
0f52c61
feat add benevolent type to preg_split
malsuke Dec 25, 2024
4c3681d
feat new feat for flag
malsuke Dec 25, 2024
c4e76c9
feat improve for flag & non-empty-string
malsuke Dec 25, 2024
68379ac
add test for PREG_SPLIT_DELIM_CAPTURE flag
malsuke Dec 25, 2024
2031d06
add test case for nonEmptySubject
malsuke Dec 26, 2024
82e4ce6
feat add if state for nonEmptySubject
malsuke Dec 26, 2024
fd496c2
feat cleanup
malsuke Dec 26, 2024
96896ca
feat cleanup
malsuke Dec 26, 2024
6ff7b8c
feat cleanup
malsuke Dec 26, 2024
c9852d5
feat add is_int assertion
malsuke Dec 26, 2024
6d1d6e9
feat fix test
malsuke Dec 26, 2024
6549506
feat fix test
malsuke Dec 26, 2024
3d51233
fix cleanup
malsuke Dec 26, 2024
540e1b2
fix cleanup
malsuke Dec 26, 2024
d48a512
fix cleanup
malsuke Dec 26, 2024
d020927
fix cleanup loop
malsuke Dec 26, 2024
13937b8
fix __benevolent usage
malsuke Jan 14, 2025
99b2d4d
fix test
malsuke Jan 14, 2025
bd4b7d2
fix test
malsuke Jan 14, 2025
eb3e9f4
fix test
malsuke Jan 14, 2025
daa3072
fix test
malsuke Jan 14, 2025
4672297
fix coding style
malsuke Jan 14, 2025
b809edc
fix: use utils function, return point, allow numeric-string
malsuke Mar 7, 2025
c96736b
feat: add test for Error
malsuke Mar 7, 2025
de4c495
feat: migrate validation to private method
malsuke Mar 7, 2025
a305dab
fix: coding style
malsuke Mar 7, 2025
3f7bdcc
fix: coding style
malsuke Mar 7, 2025
658826a
feat: change variable name, fix: check type of limit/flag
malsuke Mar 11, 2025
ca78451
add: add test for scaler value
malsuke Mar 11, 2025
c896b1b
fix: lint
malsuke Mar 11, 2025
5949c79
feat: return union false
malsuke Mar 12, 2025
a54bd80
feat: Handle case when preg_split returns false
malsuke Apr 17, 2025
1ee1a79
fix: for using ConstantArrayTypeBuilder and UnionType
malsuke May 15, 2025
798fa23
fix: cleanup
malsuke May 15, 2025
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
Prev Previous commit
Next Next commit
fix: for using ConstantArrayTypeBuilder and UnionType
  • Loading branch information
malsuke committed May 15, 2025
commit 1ee1a792c4d4d681d74e52724e9ccd907f02116b
18 changes: 11 additions & 7 deletions src/Type/Php/PregSplitDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use function count;
use function is_array;
use function is_int;
Expand Down Expand Up @@ -113,13 +114,16 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
$returnStringType = new StringType();
}

$capturedArrayType = new ConstantArrayType(
[new ConstantIntegerType(0), new ConstantIntegerType(1)],
[$returnStringType, IntegerRangeType::fromInterval(0, null)],
[2],
[],
TrinaryLogic::createYes(),
$arrayTypeBuilder = ConstantArrayTypeBuilder::createEmpty();
$arrayTypeBuilder->setOffsetValueType(
new ConstantIntegerType(0),
$returnStringType
);
$arrayTypeBuilder->setOffsetValueType(
new ConstantIntegerType(1),
IntegerRangeType::fromInterval(0, null)
);
$capturedArrayType = $arrayTypeBuilder->getArray();

$returnInternalValueType = $returnStringType;
if ($capturesOffset !== null) {
Expand Down Expand Up @@ -203,7 +207,7 @@ private function isValidPattern(string $pattern): bool

private function isIntOrStringValue(Type $type): bool
{
return $type->isInteger()->yes() || $type->isString()->yes() || $type->isConstantScalarValue()->yes();
return (new UnionType([new IntegerType(), new StringType()]))->isSuperTypeOf($type)->yes();
}

}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy