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...
503
}
504
505
/**
506
* This method will auto-detect your server environment for UTF-8 support.
507
*
508
* @return true|null
509
*
510
* @internal <p>You don't need to run it manually, it will be triggered if it's needed.</p>
511
*/
512
5
public static function checkForSupport()
513
{
514
5
if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
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>
4998
* @param bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces.</p>
4999
* @param bool $keep_bidi_unicode_controls [optional] <p>Set to true, to keep non-printable (for the web)
5000
* bidirectional text chars.</p>
5001
* @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>
5002
*
5003
* @psalm-pure
5004
*
5005
* @return string
5006
* <p>A string with normalized whitespace.</p>
5007
*/
5008
public static function normalize_whitespace(
5009
string $str,
5010
bool $keep_non_breaking_space = false,
5011
bool $keep_bidi_unicode_controls = false,
5012
bool $normalize_control_characters = false
5013
): string {
5014
61
return ASCII::normalize_whitespace(
5015
61
$str,
5016
61
$keep_non_breaking_space,
5017
61
$keep_bidi_unicode_controls,
5018
61
$normalize_control_characters
5019
);
5020
}
5021
5022
/**
5023
* Calculates Unicode code point of the given UTF-8 encoded character.
5024
*
5025
* INFO: opposite to UTF8::chr()
5026
*
5027
* EXAMPLE: <code>UTF8::ord('☃'); // 0x2603</code>
5028
*
5029
* @param string $chr <p>The character of which to calculate code point.<p/>
5030
* @param string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
5031
*
5032
* @psalm-pure
5033
*
5034
* @return int
5035
* <p>Unicode code point of the given character,<br>
5036
* 0 on invalid UTF-8 byte sequence</p>
5037
*/
5038
public static function ord($chr, string $encoding = 'UTF-8'): int
5039
{
5040
/**
5041
* @psalm-suppress ImpureStaticVariable
5042
*
5043
* @var array<string,int>
5044
*/
5045
27
static $CHAR_CACHE = [];
5046
5047
// init
5048
27
$chr = (string) $chr;
5049
5050
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...
5622
}
5623
5624
/**
5625
* Replaces all occurrences of $search in $str by $replacement.
5626
*
5627
* @param string $str <p>The input string.</p>
5628
* @param array $search <p>The elements to search for.</p>
5629
* @param array|string $replacement <p>The string to replace with.</p>
5630
* @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...
5648
}
5649
5650
/**
5651
* 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...
5692
// 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($str, $length, $clean_utf8) returns an array which contains values of type string[] which are incompatible with the documented value type string.
Loading history...
5856
}
5857
5858
/**
5859
* alias for "UTF8::str_starts_with()"
5860
*
5861
* @param string $haystack
5862
* @param string $needle
5863
*
5864
* @psalm-pure
5865
*
5866
* @return bool
5867
*
5868
* @see UTF8::str_starts_with()
5869
* @deprecated <p>please use "UTF8::str_starts_with()"</p>
5870
*/
5871
public static function str_begins(string $haystack, string $needle): bool
5872
{
5873
1
return self::str_starts_with($haystack, $needle);
5874
}
5875
5876
/**
5877
* Returns a camelCase version of the string. Trims surrounding spaces,
5878
* capitalizes letters following digits, spaces, dashes and underscores,
5879
* and removes spaces, dashes, as well as underscores.
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[].
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($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
11931
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) . ')');
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
11931
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) . ')');
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...
12090
return '';
12091
}
12092
12093
// impossible
12094
4
if ($offset && $offset > $str_length) {
12095
return '';
12096
}
12097
12098
4
$length = $length ?? $str_length;
12099
12100
if (
12101
4
$encoding !== 'UTF-8'
12102
&&
12103
4
self::$SUPPORT['mbstring'] === false
12104
) {
12105
/**
12106
* @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.