The expression return self::str_split($str) returns an array which contains values of type string[] which are incompatible with the documented value type string.
Loading history...
495
}
496
497
/**
498
* This method will auto-detect your server environment for UTF-8 support.
499
*
500
* @return true|null
501
*
502
* @internal <p>You don't need to run it manually, it will be triggered if it's needed.</p>
503
*/
504
4
public static function checkForSupport()
505
{
506
4
if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
The expression return mb_convert_encodi...TF-8', 'HTML-ENTITIES') could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
1190
}
1191
1192
/**
1193
* Decodes a MIME header field
1194
*
1195
* @param string $str
1196
* @param string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
1197
*
1198
* @psalm-pure
1199
*
1200
* @return false|string
1201
* <p>A decoded MIME field on success,
1202
* or false if an error occurs during the decoding.</p>
1203
*/
1204
2
public static function decode_mimeheader($str, string $encoding = 'UTF-8')
1205
{
1206
2
if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
It seems like $options can also be of type null; however, parameter $options of filter_var() does only seem to accept array|integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
It seems like $definition can also be of type null; however, parameter $options of filter_var_array() does only seem to accept array|integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
This check compares calls to functions or methods with their respective definitions.
If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the
check may pick up the wrong definition and report false positives. One codebase
where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
It seems like $test3 can also be of type array; however, parameter $str of voku\helper\UTF8::count_chars() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
It seems like $test3 can also be of type array; however, parameter $str of voku\helper\UTF8::count_chars() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
* @param string $str <p>The string to be normalized.</p>
4655
* @param bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces.</p>
4656
* @param bool $keep_bidi_unicode_controls [optional] <p>Set to true, to keep non-printable (for the web)
4657
* bidirectional text chars.</p>
4658
* @param bool $normalize_control_characters [optional] <p>Set to true, to convert e.g. LINE-, PARAGRAPH-SEPARATOR with "\n" and LINE TABULATION with "\t".</p>
4659
*
4660
* @psalm-pure
4661
*
4662
* @return string
4663
* <p>A string with normalized whitespace.</p>
4664
*/
4665
61
public static function normalize_whitespace(
4666
string $str,
4667
bool $keep_non_breaking_space = false,
4668
bool $keep_bidi_unicode_controls = false,
4669
bool $normalize_control_characters = false
4670
): string {
4671
61
return ASCII::normalize_whitespace(
4672
61
$str,
4673
$keep_non_breaking_space,
4674
$keep_bidi_unicode_controls,
4675
$normalize_control_characters
4676
);
4677
}
4678
4679
/**
4680
* Calculates Unicode code point of the given UTF-8 encoded character.
4681
*
4682
* INFO: opposite to UTF8::chr()
4683
*
4684
* EXAMPLE: <code>UTF8::ord('☃'); // 0x2603</code>
4685
*
4686
* @param string $chr <p>The character of which to calculate code point.<p/>
4687
* @param string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
4688
*
4689
* @psalm-pure
4690
*
4691
* @return int
4692
* <p>Unicode code point of the given character,<br>
4693
* 0 on invalid UTF-8 byte sequence</p>
4694
*/
4695
27
public static function ord($chr, string $encoding = 'UTF-8'): int
4696
{
4697
/**
4698
* @psalm-suppress ImpureStaticVariable
4699
*
4700
* @var array<string,int>
4701
*/
4702
27
static $CHAR_CACHE = [];
4703
4704
// init
4705
27
$chr = (string) $chr;
4706
4707
27
if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
The expression $code of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like ==, or !=, or switch conditions),
values of different types might be equal.
For integer values, zero is a special case, in particular the following
results might be unexpected:
0==false// true0==null// true123==false// false123==null// false// It is often better to use strict comparison0===false// false0===null// false
The expression return self::str_ireplac...ch, $replacement, $str) could return the type string[] which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
5259
}
5260
5261
/**
5262
* Replaces all occurrences of $search in $str by $replacement.
5263
*
5264
* @param string $str <p>The input string.</p>
5265
* @param array $search <p>The elements to search for.</p>
5266
* @param array|string $replacement <p>The string to replace with.</p>
5267
* @param bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>
The expression return self::str_ireplac...ch, $replacement, $str) could return the type string[] which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
5285
}
5286
5287
/**
5288
* Replace the diamond question mark (�) and invalid-UTF8 chars with the replacement.
It seems like you do not handle an error condition for mb_substitute_character(). This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled annotation
If you suppress an error, we recommend checking for the error condition explicitly:
// For example instead of@mkdir($dir);// Better useif(@mkdir($dir)===false){thrownew\RuntimeException('The directory '.$dir.' could not be created.');}
Loading history...
5329
// the polyfill maybe return false, so cast to string
It seems like $save can also be of type true; however, parameter $substitute_character of mb_substitute_character() does only seem to accept integer|null|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
The expression return self::str_split_a...ry_to_use_mb_functions) returns the type array<mixed,string[]> which is incompatible with the documented return type string[].
The expression return mb_convert_encodi...TF-8', 'HTML-ENTITIES') could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
9212
}
9213
9214
/**
9215
* Checks if string starts with "BOM" (Byte Order Mark Character) character.
* @param string|string[] $to [optional] <p>The string being translated to to.</p>
11160
*
11161
* @psalm-pure
11162
*
11163
* @return string
11164
* <p>This function returns a copy of str, translating all occurrences of each character in "from"
11165
* to the corresponding character in "to".</p>
11166
*/
11167
2
public static function strtr(string $str, $from, $to = ''): string
11168
{
11169
2
if ($str === '') {
11170
return '';
11171
}
11172
11173
2
if ($from === $to) {
11174
return $str;
11175
}
11176
11177
2
if ($to !== '') {
11178
2
if (!\is_array($from)) {
11179
2
$from = self::str_split($from);
11180
}
11181
11182
2
if (!\is_array($to)) {
11183
2
$to = self::str_split($to);
11184
}
11185
11186
2
$count_from = \count($from);
11187
2
$count_to = \count($to);
11188
11189
2
if ($count_from !== $count_to) {
11190
2
if ($count_from > $count_to) {
11191
2
$from = \array_slice($from, 0, $count_to);
11192
2
} elseif ($count_from < $count_to) {
11193
2
$to = \array_slice($to, 0, $count_from);
11194
}
11195
}
11196
11197
2
$from = \array_combine($from, $to);
11198
2
if ($from === false) {
11199
throw new \InvalidArgumentException('The number of elements for each array isn\'t equal or the arrays are empty: (from: ' . \print_r($from, true) . ' | to: ' . \print_r($to, true) . ')');
Are you sure print_r($to, true) of type string|true can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
11199
throw new \InvalidArgumentException('The number of elements for each array isn\'t equal or the arrays are empty: (from: ' . \print_r($from, true) . ' | to: ' . /** @scrutinizer ignore-type */ \print_r($to, true) . ')');
Are you sure print_r($from, true) of type string|true can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
11199
throw new \InvalidArgumentException('The number of elements for each array isn\'t equal or the arrays are empty: (from: ' . /** @scrutinizer ignore-type */ \print_r($from, true) . ' | to: ' . \print_r($to, true) . ')');
It seems like $to can also be of type array<mixed,string[]>; however, parameter $replace of str_replace() does only seem to accept string|string[], maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
The expression $length of type integer|null is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === null instead.
In PHP, under loose comparison (like ==, or !=, or switch conditions),
values of different types might be equal.
For integer values, zero is a special case, in particular the following
results might be unexpected:
0==false// true0==null// true123==false// false123==null// false// It is often better to use strict comparison0===false// false0===null// false
Loading history...
11358
return '';
11359
}
11360
11361
// impossible
11362
4
if ($offset && $offset > $str_length) {
11363
return '';
11364
}
11365
11366
4
$length = $length ?? $str_length;
11367
11368
if (
11369
4
$encoding !== 'UTF-8'
11370
&&
11371
4
self::$SUPPORT['mbstring'] === false
11372
) {
11373
/**
11374
* @psalm-suppress ImpureFunctionCall - is is only a warning
It seems like $str can also be of type false; however, parameter $string of utf8_encode() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
$class_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $class_array = array(); before regardless.