The expression return self::str_split($str) returns an array which contains values of type array|string[] which are incompatible with the documented value type string.
Loading history...
481
}
482
483
/**
484
* This method will auto-detect your server environment for UTF-8 support.
485
*
486
* @return true|null
487
*
488
* @internal <p>You don't need to run it manually, it will be triggered if it's needed.</p>
489
*/
490
5
public static function checkForSupport()
491
{
492
5
if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
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...
5581
}
5582
5583
/**
5584
* Replaces all occurrences of $search in $str by $replacement.
5585
*
5586
* @param string $str <p>The input string.</p>
5587
* @param array $search <p>The elements to search for.</p>
5588
* @param array|string $replacement <p>The string to replace with.</p>
5589
* @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...
5607
}
5608
5609
/**
5610
* 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...
5650
// the polyfill maybe return false, so cast to string
The expression return self::str_split($str, $length, $clean_utf8) returns an array which contains values of type array|string[] which are incompatible with the documented value type string.
Loading history...
5814
}
5815
5816
/**
5817
* alias for "UTF8::str_starts_with()"
5818
*
5819
* @param string $haystack
5820
* @param string $needle
5821
*
5822
* @psalm-pure
5823
*
5824
* @return bool
5825
*
5826
* @see UTF8::str_starts_with()
5827
* @deprecated <p>please use "UTF8::str_starts_with()"</p>
5828
*/
5829
public static function str_begins(string $haystack, string $needle): bool
5830
{
5831
1
return self::str_starts_with($haystack, $needle);
5832
}
5833
5834
/**
5835
* Returns a camelCase version of the string. Trims surrounding spaces,
5836
* capitalizes letters following digits, spaces, dashes and underscores,
5837
* and removes spaces, dashes, as well as underscores.
The expression return self::substr_repl...)self::strlen($search)) 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...
7960
2
$subject,
7961
2
$replace,
7962
2
$pos,
7963
2
(int) self::strlen($search)
7964
);
7965
}
7966
7967
2
return $subject;
7968
}
7969
7970
/**
7971
* Replace the last "$search"-term with the "$replace"-term.
The expression return self::substr_repl...)self::strlen($search)) 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...
7994
2
$subject,
7995
2
$replace,
7996
2
$pos,
7997
2
(int) self::strlen($search)
7998
);
7999
}
8000
8001
2
return $subject;
8002
}
8003
8004
/**
8005
* Shuffles all the characters in the string.
8006
*
8007
* INFO: uses random algorithm which is weak for cryptography purposes
It seems like $array can also be of type null; however, parameter $array of arsort() does only seem to accept array, 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 $array can also be of type null; however, parameter $array of asort() does only seem to accept array, 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
8201
\asort(/** @scrutinizer ignore-type */ $array);
Loading history...
8202
}
8203
8204
2
return self::string($array);
8205
}
8206
8207
/**
8208
* Convert a string to an array of Unicode characters.
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) . ')');
It seems like $to can also be of type array<mixed,array> and 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...
11862
return '';
11863
}
11864
11865
// impossible
11866
4
if ($offset && $offset > $str_length) {
11867
return '';
11868
}
11869
11870
4
if ($length === null) {
11871
4
$length = (int) $str_length;
11872
} else {
11873
2
$length = (int) $length;
11874
}
11875
11876
if (
11877
4
$encoding !== 'UTF-8'
11878
&&
11879
4
self::$SUPPORT['mbstring'] === false
11880
) {
11881
/**
11882
* @psalm-suppress ImpureFunctionCall - is is only a warning
It seems like $str can also be of type false; however, parameter $data 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.