Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
8 / 8 |
Escape | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
8 / 8 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
filter | |
100.00% |
1 / 1 |
3 | |
100.00% |
5 / 5 |
<?php | |
namespace Verja\Filter; | |
use Verja\Filter; | |
class Escape extends Filter | |
{ | |
/** @var bool */ | |
protected $doubleEncode = false; | |
/** @var bool */ | |
protected $specialChars = true; | |
/** | |
* Escape constructor. | |
* | |
* @param bool $doubleEncode | |
* @param bool $specialChars | |
*/ | |
public function __construct(bool $doubleEncode = false, bool $specialChars = true) | |
{ | |
$this->doubleEncode = $doubleEncode; | |
$this->specialChars = $specialChars; | |
} | |
/** | |
* Filter $value | |
* | |
* @param mixed $value | |
* @param array $context | |
* @return mixed | |
*/ | |
public function filter($value, array $context = []) | |
{ | |
if (!is_string($value)) { | |
return $value; | |
} | |
return $this->specialChars ? | |
htmlspecialchars($value, ENT_COMPAT, ini_get('default_charset'), $this->doubleEncode) : | |
htmlentities($value, ENT_COMPAT, ini_get('default_charset'), $this->doubleEncode); | |
} | |
} |