Skip to content

Commit f9e9359

Browse files
committed
analog mb_strlen
1 parent a386394 commit f9e9359

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,12 +1551,6 @@ parameters:
15511551
count: 2
15521552
path: src/Type/Php/LtrimFunctionReturnTypeExtension.php
15531553

1554-
-
1555-
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantStringType is error\-prone and deprecated\. Use Type\:\:getConstantStrings\(\) instead\.$#'
1556-
identifier: phpstanApi.instanceofType
1557-
count: 1
1558-
path: src/Type/Php/MbStrlenFunctionReturnTypeExtension.php
1559-
15601554
-
15611555
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantStringType is error\-prone and deprecated\. Use Type\:\:getConstantStrings\(\) instead\.$#'
15621556
identifier: phpstanApi.instanceofType

src/Type/Php/MbStrlenFunctionReturnTypeExtension.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,20 @@ public function getTypeFromFunctionCall(
9292
}
9393

9494
$argType = $scope->getType($args[0]->value);
95-
$constantScalars = $argType->getConstantScalarTypes();
95+
$constantScalars = $argType->getConstantScalarValues();
9696

9797
$lengths = [];
9898
foreach ($constantScalars as $constantScalar) {
99-
$stringScalar = $constantScalar->toString();
100-
if (!($stringScalar instanceof ConstantStringType)) {
101-
$lengths = [];
102-
break;
103-
}
99+
$stringScalar = (string) $constantScalar;
104100

105101
foreach ($encodings as $encoding) {
106102
if (!$this->isSupportedEncoding($encoding)) {
107103
continue;
108104
}
109105

110-
$length = @mb_strlen($stringScalar->getValue(), $encoding);
106+
$length = @mb_strlen($stringScalar, $encoding);
111107
if ($length === false) {
112-
throw new ShouldNotHappenException(sprintf('Got false on a supported encoding %s and value %s', $encoding, var_export($stringScalar->getValue(), true)));
108+
throw new ShouldNotHappenException(sprintf('Got false on a supported encoding %s and value %s', $encoding, var_export($stringScalar, true)));
113109
}
114110
$lengths[] = $length;
115111
}

0 commit comments

Comments
 (0)