1 | <?php |
||
29 | class BaseHtmlPurifier |
||
30 | { |
||
31 | /** |
||
32 | * Passes markup through HTMLPurifier making it safe to output to end user. |
||
33 | * |
||
34 | * @param string $content The HTML content to purify |
||
35 | * @param array|\Closure|null $config The config to use for HtmlPurifier. |
||
36 | * If not specified or `null` the default config will be used. |
||
37 | * You can use an array or an anonymous function to provide configuration options: |
||
38 | * |
||
39 | * - An array will be passed to the `HTMLPurifier_Config::create()` method. |
||
40 | * - An anonymous function will be called after the config was created. |
||
41 | * The signature should be: `function($config)` where `$config` will be an |
||
42 | * instance of `HTMLPurifier_Config`. |
||
43 | * |
||
44 | * Here is a usage example of such a function: |
||
45 | * |
||
46 | * ```php |
||
47 | * // Allow the HTML5 data attribute `data-type` on `img` elements. |
||
48 | * $content = HtmlPurifier::process($content, function ($config) { |
||
49 | * $config->getHTMLDefinition(true) |
||
50 | * ->addAttribute('img', 'data-type', 'Text'); |
||
51 | * }); |
||
52 | * ``` |
||
53 | * @return string the purified HTML content. |
||
54 | */ |
||
55 | 2 | public static function process($content, $config = null) |
|
64 | |||
65 | /** |
||
66 | * Truncate a HTML string. |
||
67 | * |
||
68 | * @param string $html The HTML string to be truncated. |
||
69 | * @param int $count |
||
70 | * @param string $suffix String to append to the end of the truncated string. |
||
71 | * @param string|bool $encoding |
||
72 | * @return string |
||
73 | * @since 2.1.0 |
||
74 | */ |
||
75 | public static function truncate($html, $count, $suffix, $encoding = false) |
||
125 | |||
126 | /** |
||
127 | * Creates a HtmlPurifier configuration instance. |
||
128 | * @see \HTMLPurifier_Config::create() |
||
129 | * @param array|\Closure|null $config The config to use for HtmlPurifier. |
||
130 | * If not specified or `null` the default config will be used. |
||
131 | * You can use an array or an anonymous function to provide configuration options: |
||
132 | * |
||
133 | * - An array will be passed to the `HTMLPurifier_Config::create()` method. |
||
134 | * - An anonymous function will be called after the config was created. |
||
135 | * The signature should be: `function($config)` where `$config` will be an |
||
136 | * instance of `HTMLPurifier_Config`. |
||
137 | * |
||
138 | * Here is a usage example of such a function: |
||
139 | * |
||
140 | * ```php |
||
141 | * // Allow the HTML5 data attribute `data-type` on `img` elements. |
||
142 | * $content = HtmlPurifier::process($content, function ($config) { |
||
143 | * $config->getHTMLDefinition(true) |
||
144 | * ->addAttribute('img', 'data-type', 'Text'); |
||
145 | * }); |
||
146 | * ``` |
||
147 | * |
||
148 | * @return \HTMLPurifier_Config HTMLPurifier config instance. |
||
149 | * @throws InvalidConfigException in case "ezyang/htmlpurifier" package is not available. |
||
150 | * @since 2.1.0 |
||
151 | */ |
||
152 | 4 | public static function createConfig($config = null) |
|
171 | |||
172 | /** |
||
173 | * Allow the extended HtmlPurifier class to set some default config options. |
||
174 | * @param \HTMLPurifier_Config $config HTMLPurifier config instance. |
||
175 | * @since 2.0.3 |
||
176 | */ |
||
177 | 4 | protected static function configure($config) |
|
180 | } |
||
181 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.