public function __construct($encoding = null)
{
if ($encoding !== null) {
- $encoding = (string) $encoding;
+ if (! is_string($encoding)) {
+ throw new Exception\InvalidArgumentException(
+ get_class($this) . ' constructor parameter must be a string, received ' . gettype($encoding)
+ );
+ }
if ($encoding === '') {
throw new Exception\InvalidArgumentException(
get_class($this) . ' constructor parameter does not allow a blank value'
}
$encoding = strtolower($encoding);
- if (!in_array($encoding, $this->supportedEncodings)) {
+ if (! in_array($encoding, $this->supportedEncodings)) {
throw new Exception\InvalidArgumentException(
'Value of \'' . $encoding . '\' passed to ' . get_class($this)
. ' constructor parameter is invalid. Provide an encoding supported by htmlspecialchars()'
$result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
}
- if (!$this->isUtf8($result)) {
+ if (! $this->isUtf8($result)) {
throw new Exception\RuntimeException(
sprintf('String to be escaped was not valid UTF-8 or could not be converted: %s', $result)
);