| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * @author Florian Schmitz, Brett Zamir, Nikolay Matsievsky, Cedric Morin, Christopher Finke, Mark Scherer, Tobias Bäthge |
| 8 | 8 | * @since 1.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | // Prohibit direct script loading. |
| 12 | 14 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 15 | |
| 14 | 16 | /** |
| @@ -42,17 +44,17 @@ | ||
| 42 | 44 | * Defines constants. |
| 43 | 45 | * |
| 44 | 46 | * @since 1.0.0 |
| 45 | 47 | */ |
| 46 | - const AT_START = 1; | |
| 47 | - const AT_END = 2; | |
| 48 | - const SEL_START = 3; | |
| 49 | - const SEL_END = 4; | |
| 50 | - const PROPERTY = 5; | |
| 51 | - const VALUE = 6; | |
| 52 | - const COMMENT = 7; | |
| 53 | - const IMPORTANT_COMMENT = 8; | |
| 54 | - const DEFAULT_AT = 41; | |
| 48 | + public const AT_START = 1; | |
| 49 | + public const AT_END = 2; | |
| 50 | + public const SEL_START = 3; | |
| 51 | + public const SEL_END = 4; | |
| 52 | + public const PROPERTY = 5; | |
| 53 | + public const VALUE = 6; | |
| 54 | + public const COMMENT = 7; | |
| 55 | + public const IMPORTANT_COMMENT = 8; | |
| 56 | + public const DEFAULT_AT = 41; | |
| 55 | 57 | |
| 56 | 58 | /** |
| 57 | 59 | * The parsed CSS. |
| 58 | 60 | * |
| @@ -58,67 +60,59 @@ | ||
| 58 | 60 | * |
| 59 | 61 | * This array is empty if preserve_css is on. |
| 60 | 62 | * |
| 61 | 63 | * @since 1.0.0 |
| 62 | - * @var array | |
| 63 | 64 | */ |
| 64 | - public $css = array(); | |
| 65 | + public array $css = array(); | |
| 65 | 66 | |
| 66 | 67 | /** |
| 67 | 68 | * The raw parsed CSS. |
| 68 | 69 | * |
| 69 | 70 | * @since 1.0.0 |
| 70 | - * @var array | |
| 71 | 71 | */ |
| 72 | - public $tokens = array(); | |
| 72 | + public array $tokens = array(); | |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Instance of the CSS Printer class. |
| 76 | 76 | * |
| 77 | 77 | * @since 1.0.0 |
| 78 | - * @var TablePress_CSSTidy_Print | |
| 79 | 78 | */ |
| 80 | - public $print; | |
| 79 | + public \TablePress_CSSTidy_Print $print; | |
| 81 | 80 | |
| 82 | 81 | /** |
| 83 | 82 | * Instance of the CSS Optimiser class. |
| 84 | 83 | * |
| 85 | 84 | * @since 1.0.0 |
| 86 | - * @var TablePress_CSSTidy_Optimise | |
| 87 | 85 | */ |
| 88 | - public $optimise; | |
| 86 | + public \TablePress_CSSTidy_Optimise $optimise; | |
| 89 | 87 | |
| 90 | 88 | /** |
| 91 | 89 | * The CSS charset. |
| 92 | 90 | * |
| 93 | 91 | * @since 1.0.0 |
| 94 | - * @var string | |
| 95 | 92 | */ |
| 96 | - public $charset = ''; | |
| 93 | + public string $charset = ''; | |
| 97 | 94 | |
| 98 | 95 | /** |
| 99 | 96 | * All @import URLs. |
| 100 | 97 | * |
| 101 | 98 | * @since 1.0.0 |
| 102 | - * @var array | |
| 103 | 99 | */ |
| 104 | - public $import = array(); | |
| 100 | + public array $import = array(); | |
| 105 | 101 | |
| 106 | 102 | /** |
| 107 | 103 | * The namespace. |
| 108 | 104 | * |
| 109 | 105 | * @since 1.0.0 |
| 110 | - * @var string | |
| 111 | 106 | */ |
| 112 | - public $namespace = ''; | |
| 107 | + public string $namespace = ''; | |
| 113 | 108 | |
| 114 | 109 | /** |
| 115 | 110 | * The settings. |
| 116 | 111 | * |
| 117 | 112 | * @since 1.0.0 |
| 118 | - * @var array | |
| 119 | 113 | */ |
| 120 | - protected $settings = array(); | |
| 114 | + protected array $settings = array(); | |
| 121 | 115 | |
| 122 | 116 | /** |
| 123 | 117 | * The parser-status. |
| 124 | 118 | * |
| @@ -130,19 +124,17 @@ | ||
| 130 | 124 | * - ic = in comment (ignore everything) |
| 131 | 125 | * - at = in @-block |
| 132 | 126 | * |
| 133 | 127 | * @since 1.0.0 |
| 134 | - * @var string | |
| 135 | 128 | */ |
| 136 | - protected $status = 'is'; | |
| 129 | + protected string $status = 'is'; | |
| 137 | 130 | |
| 138 | 131 | /** |
| 139 | 132 | * The current at rule (@media). |
| 140 | 133 | * |
| 141 | 134 | * @since 1.0.0 |
| 142 | - * @var string | |
| 143 | 135 | */ |
| 144 | - public $at = ''; | |
| 136 | + public string $at = ''; | |
| 145 | 137 | |
| 146 | 138 | /** |
| 147 | 139 | * The at rule for next selector (during @font-face or other @). |
| 148 | 140 | * |
| @@ -154,35 +146,31 @@ | ||
| 154 | 146 | /** |
| 155 | 147 | * The current selector. |
| 156 | 148 | * |
| 157 | 149 | * @since 1.0.0 |
| 158 | - * @var string | |
| 159 | 150 | */ |
| 160 | - public $selector = ''; | |
| 151 | + public string $selector = ''; | |
| 161 | 152 | |
| 162 | 153 | /** |
| 163 | 154 | * The current property. |
| 164 | 155 | * |
| 165 | 156 | * @since 1.0.0 |
| 166 | - * @var string | |
| 167 | 157 | */ |
| 168 | - public $property = ''; | |
| 158 | + public string $property = ''; | |
| 169 | 159 | |
| 170 | 160 | /** |
| 171 | 161 | * The position of , in selectors. |
| 172 | 162 | * |
| 173 | 163 | * @since 1.0.0 |
| 174 | - * @var array | |
| 175 | 164 | */ |
| 176 | - protected $sel_separate = array(); | |
| 165 | + protected array $sel_separate = array(); | |
| 177 | 166 | |
| 178 | 167 | /** |
| 179 | 168 | * The current value. |
| 180 | 169 | * |
| 181 | 170 | * @since 1.0.0 |
| 182 | - * @var string | |
| 183 | 171 | */ |
| 184 | - public $value = ''; | |
| 172 | + public string $value = ''; | |
| 185 | 173 | |
| 186 | 174 | /** |
| 187 | 175 | * The current sub-value. |
| 188 | 176 | * |
| @@ -191,107 +179,94 @@ | ||
| 191 | 179 | * "url(foo.png)", "red", and "no-repeat" are sub-values, |
| 192 | 180 | * separated by whitespace. |
| 193 | 181 | * |
| 194 | 182 | * @since 1.0.0 |
| 195 | - * @var string | |
| 196 | 183 | */ |
| 197 | - public $sub_value = ''; | |
| 184 | + public string $sub_value = ''; | |
| 198 | 185 | |
| 199 | 186 | /** |
| 200 | 187 | * All sub-values for a property. |
| 201 | 188 | * |
| 202 | 189 | * @since 1.0.0 |
| 203 | - * @var array | |
| 204 | 190 | */ |
| 205 | - protected $sub_value_arr = array(); | |
| 191 | + protected array $sub_value_arr = array(); | |
| 206 | 192 | |
| 207 | 193 | /** |
| 208 | 194 | * The stack of characters that opened the current strings. |
| 209 | 195 | * |
| 210 | 196 | * @since 1.0.0 |
| 211 | - * @var array | |
| 212 | 197 | */ |
| 213 | - public $str_char = array(); | |
| 198 | + public array $str_char = array(); | |
| 214 | 199 | |
| 215 | 200 | /** |
| 216 | 201 | * [$cur_string description] |
| 217 | 202 | * |
| 218 | 203 | * @since 1.0.0 |
| 219 | - * @var array | |
| 220 | 204 | */ |
| 221 | - public $cur_string = array(); | |
| 205 | + public array $cur_string = array(); | |
| 222 | 206 | |
| 223 | 207 | /** |
| 224 | 208 | * Status from which the parser switched to ic or instr |
| 225 | 209 | * |
| 226 | 210 | * @since 1.0.0 |
| 227 | - * @var array | |
| 228 | 211 | */ |
| 229 | - protected $from = array(); | |
| 212 | + protected array $from = array(); | |
| 230 | 213 | |
| 231 | 214 | /** |
| 232 | 215 | * True if in invalid at-rule. |
| 233 | 216 | * |
| 234 | 217 | * @since 1.0.0 |
| 235 | - * @var bool | |
| 236 | 218 | */ |
| 237 | - protected $invalid_at = false; | |
| 219 | + protected bool $invalid_at = false; | |
| 238 | 220 | |
| 239 | 221 | /** |
| 240 | 222 | * True if something has been added to the current selector. |
| 241 | 223 | * |
| 242 | 224 | * @since 1.0.0 |
| 243 | - * @var bool | |
| 244 | 225 | */ |
| 245 | - protected $added = false; | |
| 226 | + protected bool $added = false; | |
| 246 | 227 | |
| 247 | 228 | /** |
| 248 | 229 | * The message log. |
| 249 | 230 | * |
| 250 | 231 | * @since 1.0.0 |
| 251 | - * @var array | |
| 252 | 232 | */ |
| 253 | - public $log = array(); | |
| 233 | + public array $log = array(); | |
| 254 | 234 | |
| 255 | 235 | /** |
| 256 | 236 | * The line number. |
| 257 | 237 | * |
| 258 | 238 | * @since 1.0.0 |
| 259 | - * @var int | |
| 260 | 239 | */ |
| 261 | - protected $line = 1; | |
| 240 | + protected int $line = 1; | |
| 262 | 241 | |
| 263 | 242 | /** |
| 264 | 243 | * Marks if we need to leave quotes for a string. |
| 265 | 244 | * |
| 266 | 245 | * @since 1.0.0 |
| 267 | - * @var array | |
| 268 | 246 | */ |
| 269 | - protected $quoted_string = array(); | |
| 247 | + protected array $quoted_string = array(); | |
| 270 | 248 | |
| 271 | 249 | /** |
| 272 | 250 | * List of tokens. |
| 273 | 251 | * |
| 274 | 252 | * @since 1.0.0 |
| 275 | - * @var string | |
| 276 | 253 | */ |
| 277 | - protected $tokens_list = ''; | |
| 254 | + protected string $tokens_list = ''; | |
| 278 | 255 | |
| 279 | 256 | /** |
| 280 | 257 | * Various CSS Data for CSSTidy. |
| 281 | 258 | * |
| 282 | 259 | * @since 1.0.0 |
| 283 | - * @var array | |
| 284 | 260 | */ |
| 285 | - public $data = array(); | |
| 261 | + public array $data = array(); | |
| 286 | 262 | |
| 287 | 263 | /** |
| 288 | 264 | * The output templates. |
| 289 | 265 | * |
| 290 | 266 | * @since 1.0.0 |
| 291 | - * @var array | |
| 292 | 267 | */ |
| 293 | - public $template = array(); | |
| 268 | + public array $template = array(); | |
| 294 | 269 | |
| 295 | 270 | /** |
| 296 | 271 | * Loads standard template and sets default settings. |
| 297 | 272 | * |
| @@ -534,9 +509,9 @@ | ||
| 534 | 509 | * @return bool Whether the CSS code could be parsed successfully. |
| 535 | 510 | */ |
| 536 | 511 | public function parse( string $a_string ): bool { |
| 537 | 512 | // Temporarily set locale to en_US in order to handle floats properly. |
| 538 | - $old = @setlocale( LC_ALL, 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 513 | + $old = @setlocale( LC_ALL, '0' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 539 | 514 | @setlocale( LC_ALL, 'C' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 540 | 515 | |
| 541 | 516 | $at_rules = &$this->data['csstidy']['at_rules']; |
| 542 | 517 | $quoted_string_properties = &$this->data['csstidy']['quoted_string_properties']; |
| @@ -637,9 +612,9 @@ | ||
| 637 | 612 | } |
| 638 | 613 | } elseif ( '{' === $a_string[ $i ] ) { |
| 639 | 614 | $this->status = 'ip'; |
| 640 | 615 | if ( '' === $this->at ) { |
| 641 | - $this->at = $this->css_new_media_section( $this->at, self::DEFAULT_AT ); | |
| 616 | + $this->at = $this->css_new_media_section( $this->at, (string) self::DEFAULT_AT ); | |
| 642 | 617 | } |
| 643 | 618 | $this->selector = $this->css_new_selector( $this->at, $this->selector ); |
| 644 | 619 | $this->_add_token( self::SEL_START, $this->selector ); |
| 645 | 620 | $this->added = false; |
| @@ -722,9 +697,9 @@ | ||
| 722 | 697 | $this->sub_value = trim( $this->sub_value ) . ','; |
| 723 | 698 | } elseif ( '\\' === $a_string[ $i ] ) { |
| 724 | 699 | $this->sub_value .= $this->_unicode( $a_string, $i ); |
| 725 | 700 | } elseif ( ';' === $a_string[ $i ] || $pn ) { |
| 726 | - if ( '@' === $this->selector[0] && isset( $at_rules[ substr( $this->selector, 1 ) ] ) && 'iv' === $at_rules[ substr( $this->selector, 1 ) ] ) { | |
| 701 | + if ( '' !== $this->selector && '@' === $this->selector[0] && isset( $at_rules[ substr( $this->selector, 1 ) ] ) && 'iv' === $at_rules[ substr( $this->selector, 1 ) ] ) { | |
| 727 | 702 | $this->status = 'is'; |
| 728 | 703 | |
| 729 | 704 | switch ( $this->selector ) { |
| 730 | 705 | case '@charset': |
| @@ -765,9 +740,9 @@ | ||
| 765 | 740 | $this->sub_value .= $a_string[ $i ]; |
| 766 | 741 | } |
| 767 | 742 | if ( ( '}' === $a_string[ $i ] || ';' === $a_string[ $i ] || $pn ) && ! empty( $this->selector ) ) { |
| 768 | 743 | if ( '' === $this->at ) { |
| 769 | - $this->at = $this->css_new_media_section( $this->at, self::DEFAULT_AT ); | |
| 744 | + $this->at = $this->css_new_media_section( $this->at, (string) self::DEFAULT_AT ); | |
| 770 | 745 | } |
| 771 | 746 | |
| 772 | 747 | // Case settings. |
| 773 | 748 | if ( $this->get_cfg( 'lowercase_s' ) ) { |